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

hub.exec.boto3.client.globalaccelerator.advertise_byoip_cidr
hub.exec.boto3.client.globalaccelerator.deprovision_byoip_cidr
hub.exec.boto3.client.globalaccelerator.list_byoip_cidrs
hub.exec.boto3.client.globalaccelerator.provision_byoip_cidr
hub.exec.boto3.client.globalaccelerator.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)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Provisions an IP address range to use with your AWS 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. For more information, see Bring Your Own IP Addresses (BYOIP) in the AWS Global Accelerator
    Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cidr(Text): The public IPv4 address range, in CIDR notation. The most specific IP prefix that you can
            specify is /24. The address range cannot overlap with another address range that you've brought
            to this or another Region.
        cidr_authorization_context(Dict): A signed document that proves that you are authorized to bring the specified IP address range to
            Amazon using BYOIP.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.globalaccelerator.provision_byoip_cidr(
                ctx,
                
                
                **{"Cidr": cidr, "CidrAuthorizationContext": cidr_authorization_context}
            )
            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.globalaccelerator.list_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 to use with your AWS 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 by using WithdrawByoipCidr and you must not have any accelerators that are using static
    IP addresses allocated from its address range.  For more information, see Bring Your Own IP Addresses (BYOIP) in
    the AWS Global Accelerator Developer Guide.

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

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

