"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.ec2.create_managed_prefix_list
hub.exec.boto3.client.ec2.delete_managed_prefix_list
hub.exec.boto3.client.ec2.describe_managed_prefix_lists
hub.exec.boto3.client.ec2.modify_managed_prefix_list
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, prefix_list_name: Text, max_entries: int, address_family: Text, entries: List = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a managed prefix list. You can specify one or more entries for the prefix list. Each entry consists of a
    CIDR block and an optional description. You must specify the maximum number of entries for the prefix list. The
    maximum number of entries cannot be changed later.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        prefix_list_name(Text): A name for the prefix list. Constraints: Up to 255 characters in length. The name cannot start
            with com.amazonaws.
        entries(List, optional): One or more entries for the prefix list. Defaults to None.
        max_entries(int): The maximum number of entries for the prefix list.
        tag_specifications(List, optional): The tags to apply to the prefix list during creation. Defaults to None.
        address_family(Text): The IP address type. Valid Values: IPv4 | IPv6.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.managed_prefix_list.present:
                - name: value
                - prefix_list_name: value
                - max_entries: value
                - address_family: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.managed_prefix_list.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.ec2.describe_managed_prefix_lists(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_managed_prefix_list(
                ctx,
                DryRun=ctx.test,
                ClientToken=name,
                **{"PrefixListName": prefix_list_name, "Entries": entries, "MaxEntries": max_entries, "TagSpecifications": tag_specifications, "AddressFamily": address_family}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.ec2.describe_managed_prefix_lists(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, prefix_list_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified managed prefix list. You must first remove all references to the prefix list in your
    resources.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        prefix_list_id(Text): The ID of the prefix list.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ec2.managed_prefix_list.absent:
                - name: value
                - prefix_list_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.managed_prefix_list.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.ec2.describe_managed_prefix_lists(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.delete_managed_prefix_list(
                ctx,
                DryRun=ctx.test,
                
                **{"PrefixListId": prefix_list_id}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.ec2.describe_managed_prefix_lists(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

