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

hub.exec.boto3.client.elbv2.create_load_balancer
hub.exec.boto3.client.elbv2.delete_load_balancer
hub.exec.boto3.client.elbv2.describe_load_balancers
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, subnets: List = None, subnet_mappings: List = None, security_groups: List = None, scheme: Text = None, tags: List = None, type_: Text = None, ip_address_type: Text = None, customer_owned_ipv4_pool: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Application Load Balancer, Network Load Balancer, or Gateway Load Balancer. For more information, see
    the following:    Application Load Balancers     Network Load Balancers     Gateway Load Balancers    This
    operation is idempotent, which means that it completes at most one time. If you attempt to create multiple load
    balancers with the same settings, each call succeeds.

    Args:
        name(Text): The name of the load balancer. This name must be unique per region per account, can have a
            maximum of 32 characters, must contain only alphanumeric characters or hyphens, must not begin
            or end with a hyphen, and must not begin with "internal-".
        subnets(List, optional): The IDs of the public subnets. You can specify only one subnet per Availability Zone. You must
            specify either subnets or subnet mappings. [Application Load Balancers] You must specify subnets
            from at least two Availability Zones. [Application Load Balancers on Outposts] You must specify
            one Outpost subnet. [Application Load Balancers on Local Zones] You can specify subnets from one
            or more Local Zones. [Network Load Balancers] You can specify subnets from one or more
            Availability Zones. [Gateway Load Balancers] You can specify subnets from one or more
            Availability Zones. Defaults to None.
        subnet_mappings(List, optional): The IDs of the public subnets. You can specify only one subnet per Availability Zone. You must
            specify either subnets or subnet mappings. [Application Load Balancers] You must specify subnets
            from at least two Availability Zones. You cannot specify Elastic IP addresses for your subnets.
            [Application Load Balancers on Outposts] You must specify one Outpost subnet. [Application Load
            Balancers on Local Zones] You can specify subnets from one or more Local Zones. [Network Load
            Balancers] You can specify subnets from one or more Availability Zones. You can specify one
            Elastic IP address per subnet if you need static IP addresses for your internet-facing load
            balancer. For internal load balancers, you can specify one private IP address per subnet from
            the IPv4 range of the subnet. For internet-facing load balancer, you can specify one IPv6
            address per subnet. [Gateway Load Balancers] You can specify subnets from one or more
            Availability Zones. You cannot specify Elastic IP addresses for your subnets. Defaults to None.
        security_groups(List, optional): [Application Load Balancers] The IDs of the security groups for the load balancer. Defaults to None.
        scheme(Text, optional): The nodes of an Internet-facing load balancer have public IP addresses. The DNS name of an
            Internet-facing load balancer is publicly resolvable to the public IP addresses of the nodes.
            Therefore, Internet-facing load balancers can route requests from clients over the internet. The
            nodes of an internal load balancer have only private IP addresses. The DNS name of an internal
            load balancer is publicly resolvable to the private IP addresses of the nodes. Therefore,
            internal load balancers can route requests only from clients with access to the VPC for the load
            balancer. The default is an Internet-facing load balancer. You cannot specify a scheme for a
            Gateway Load Balancer. Defaults to None.
        tags(List, optional): The tags to assign to the load balancer. Defaults to None.
        type_(Text, optional): The type of load balancer. The default is application. Defaults to None.
        ip_address_type(Text, optional): The type of IP addresses used by the subnets for your load balancer. The possible values are
            ipv4 (for IPv4 addresses) and dualstack (for IPv4 and IPv6 addresses). Internal load balancers
            must use ipv4. Defaults to None.
        customer_owned_ipv4_pool(Text, optional): [Application Load Balancers on Outposts] The ID of the customer-owned address pool (CoIP pool). Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.elbv2.load_balancer.present:
                - name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)

    
    before = await hub.exec.boto3.client.elbv2.describe_load_balancers(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.elbv2.create_load_balancer(
                ctx,
                
                
                **{"Name": name, "Subnets": subnets, "SubnetMappings": subnet_mappings, "SecurityGroups": security_groups, "Scheme": scheme, "Tags": tags, "Type": type_, "IpAddressType": ip_address_type, "CustomerOwnedIpv4Pool": customer_owned_ipv4_pool}
            )
            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.elbv2.describe_load_balancers(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, load_balancer_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified Application Load Balancer, Network Load Balancer, or Gateway Load Balancer. Deleting a
    load balancer also deletes its listeners. You can't delete a load balancer if deletion protection is enabled. If
    the load balancer does not exist or has already been deleted, the call succeeds. Deleting a load balancer does
    not affect its registered targets. For example, your EC2 instances continue to run and are still registered to
    their target groups. If you no longer need these EC2 instances, you can stop or terminate them.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        load_balancer_arn(Text): The Amazon Resource Name (ARN) of the load balancer.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

