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

hub.exec.boto3.client.ec2.advertise_byoip_cidr
hub.exec.boto3.client.ec2.deprovision_byoip_cidr
hub.exec.boto3.client.ec2.describe_byoip_cidrs
hub.exec.boto3.client.ec2.provision_byoip_cidr
hub.exec.boto3.client.ec2.withdraw_byoip_cidr
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, cidr: Text, cidr_authorization_context: Dict = None, publicly_advertisable: bool = None, description: Text = None, pool_tag_specifications: List = None, multi_region: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Provisions an IPv4 or IPv6 address range for use with your Amazon Web Services resources through bring your own
    IP addresses (BYOIP) and creates a corresponding address pool. After the address range is provisioned, it is
    ready to be advertised using AdvertiseByoipCidr. Amazon Web Services verifies that you own the address range and
    are authorized to advertise it. You must ensure that the address range is registered to you and that you created
    an RPKI ROA to authorize Amazon ASNs 16509 and 14618 to advertise the address range. For more information, see
    Bring your own IP addresses (BYOIP) in the Amazon Elastic Compute Cloud User Guide. Provisioning an address
    range is an asynchronous operation, so the call returns immediately, but the address range is not ready to use
    until its status changes from pending-provision to provisioned. To monitor the status of an address range, use
    DescribeByoipCidrs. To allocate an Elastic IP address from your IPv4 address pool, use AllocateAddress with
    either the specific address from the address pool or the ID of the address pool.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cidr(Text): The public IPv4 or IPv6 address range, in CIDR notation. The most specific IPv4 prefix that you
            can specify is /24. The most specific IPv6 prefix you can specify is /56. The address range
            cannot overlap with another address range that you've brought to this or another Region.
        cidr_authorization_context(Dict, optional): A signed document that proves that you are authorized to bring the specified IP address range to
            Amazon using BYOIP. Defaults to None.
        publicly_advertisable(bool, optional): (IPv6 only) Indicate whether the address range will be publicly advertised to the internet.
            Default: true. Defaults to None.
        description(Text, optional): A description for the address range and the address pool. Defaults to None.
        pool_tag_specifications(List, optional): The tags to apply to the address pool. Defaults to None.
        multi_region(bool, optional): Reserved. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.byoip_cidr.present:
                - name: value
                - cidr: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.byoip_cidr.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_byoip_cidrs(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.provision_byoip_cidr(
                ctx,
                DryRun=ctx.test,
                
                **{"Cidr": cidr, "CidrAuthorizationContext": cidr_authorization_context, "PubliclyAdvertisable": publicly_advertisable, "Description": description, "PoolTagSpecifications": pool_tag_specifications, "MultiRegion": multi_region}
            )
            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_byoip_cidrs(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, cidr: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Releases the specified address range that you provisioned for use with your Amazon Web Services resources
    through bring your own IP addresses (BYOIP) and deletes the corresponding address pool. Before you can release
    an address range, you must stop advertising it using WithdrawByoipCidr and you must not have any IP addresses
    allocated from its address range.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cidr(Text): The address range, in CIDR notation. The prefix must be the same prefix that you specified when
            you provisioned the address range.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ec2.byoip_cidr.absent:
                - name: value
                - cidr: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.byoip_cidr.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_byoip_cidrs(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.deprovision_byoip_cidr(
                ctx,
                DryRun=ctx.test,
                
                **{"Cidr": cidr}
            )
            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_byoip_cidrs(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

