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

hub.exec.boto3.client.ec2.create_customer_gateway
hub.exec.boto3.client.ec2.delete_customer_gateway
hub.exec.boto3.client.ec2.describe_customer_gateways
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, bgp_asn: int, type_: Text, public_ip: Text = None, certificate_arn: Text = None, tag_specifications: List = None, device_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Provides information to AWS about your VPN customer gateway device. The customer gateway is the appliance at
    your end of the VPN connection. (The device on the AWS side of the VPN connection is the virtual private
    gateway.) You must provide the internet-routable IP address of the customer gateway's external interface. The IP
    address must be static and can be behind a device performing network address translation (NAT). For devices that
    use Border Gateway Protocol (BGP), you can also provide the device's BGP Autonomous System Number (ASN). You can
    use an existing ASN assigned to your network. If you don't have an ASN already, you can use a private ASN (in
    the 64512 - 65534 range).  Amazon EC2 supports all 4-byte ASN numbers in the range of 1 - 2147483647, with the
    exception of the following:   7224 - reserved in the us-east-1 Region   9059 - reserved in the eu-west-1 Region
    17943 - reserved in the ap-southeast-1 Region   10124 - reserved in the ap-northeast-1 Region    For more
    information, see AWS Site-to-Site VPN in the AWS Site-to-Site VPN User Guide.  To create more than one customer
    gateway with the same VPN type, IP address, and BGP ASN, specify a unique device name for each customer gateway.
    Identical requests return information about the existing customer gateway and do not create new customer
    gateways.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bgp_asn(int): For devices that support BGP, the customer gateway's BGP ASN. Default: 65000.
        public_ip(Text, optional): The Internet-routable IP address for the customer gateway's outside interface. The address must
            be static. Defaults to None.
        certificate_arn(Text, optional): The Amazon Resource Name (ARN) for the customer gateway certificate. Defaults to None.
        type_(Text): The type of VPN connection that this customer gateway supports (ipsec.1).
        tag_specifications(List, optional): The tags to apply to the customer gateway. Defaults to None.
        device_name(Text, optional): A name for the customer gateway device. Length Constraints: Up to 255 characters. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_customer_gateway(
                ctx,
                DryRun=ctx.test,
                
                **{"BgpAsn": bgp_asn, "PublicIp": public_ip, "CertificateArn": certificate_arn, "Type": type_, "TagSpecifications": tag_specifications, "DeviceName": device_name}
            )
            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_customer_gateways(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, customer_gateway_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified customer gateway. You must delete the VPN connection before you can delete the customer
    gateway.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        customer_gateway_id(Text): The ID of the customer gateway.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

