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

hub.exec.boto3.client.ec2.create_vpc_endpoint
hub.exec.boto3.client.ec2.delete_vpc_endpoints
hub.exec.boto3.client.ec2.describe_vpc_endpoints
hub.exec.boto3.client.ec2.modify_vpc_endpoint
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, vpc_id: Text, service_name: Text, vpc_endpoint_type: Text = None, policy_document: Text = None, route_table_ids: List = None, subnet_ids: List = None, security_group_ids: List = None, private_dns_enabled: bool = None, tag_specifications: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a VPC endpoint for a specified service. An endpoint enables you to create a private connection between
    your VPC and the service. The service may be provided by AWS, an AWS Marketplace Partner, or another AWS
    account. For more information, see VPC Endpoints in the Amazon Virtual Private Cloud User Guide. A gateway
    endpoint serves as a target for a route in your route table for traffic destined for the AWS service. You can
    specify an endpoint policy to attach to the endpoint, which will control access to the service from your VPC.
    You can also specify the VPC route tables that use the endpoint. An interface endpoint is a network interface in
    your subnet that serves as an endpoint for communicating with the specified service. You can specify the subnets
    in which to create an endpoint, and the security groups to associate with the endpoint network interface. A
    GatewayLoadBalancer endpoint is a network interface in your subnet that serves an endpoint for communicating
    with a Gateway Load Balancer that you've configured as a VPC endpoint service. Use DescribeVpcEndpointServices
    to get a list of supported services.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        vpc_endpoint_type(Text, optional): The type of endpoint. Default: Gateway. Defaults to None.
        vpc_id(Text): The ID of the VPC in which the endpoint will be used.
        service_name(Text): The service name. To get a list of available services, use the DescribeVpcEndpointServices
            request, or get the name from the service provider.
        policy_document(Text, optional): (Interface and gateway endpoints) A policy to attach to the endpoint that controls access to the
            service. The policy must be in valid JSON format. If this parameter is not specified, we attach
            a default policy that allows full access to the service. Defaults to None.
        route_table_ids(List, optional): (Gateway endpoint) One or more route table IDs. Defaults to None.
        subnet_ids(List, optional): (Interface and Gateway Load Balancer endpoints) The ID of one or more subnets in which to create
            an endpoint network interface. For a Gateway Load Balancer endpoint, you can specify one subnet
            only. Defaults to None.
        security_group_ids(List, optional): (Interface endpoint) The ID of one or more security groups to associate with the endpoint
            network interface. Defaults to None.
        private_dns_enabled(bool, optional): (Interface endpoint) Indicates whether to associate a private hosted zone with the specified
            VPC. The private hosted zone contains a record set for the default public DNS name for the
            service for the Region (for example, kinesis.us-east-1.amazonaws.com), which resolves to the
            private IP addresses of the endpoint network interfaces in the VPC. This enables you to make
            requests to the default public DNS name for the service instead of the public DNS names that are
            automatically generated by the VPC endpoint service. To use a private hosted zone, you must set
            the following VPC attributes to true: enableDnsHostnames and enableDnsSupport. Use
            ModifyVpcAttribute to set the VPC attributes. Default: true. Defaults to None.
        tag_specifications(List, optional): The tags to associate with the endpoint. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_vpc_endpoint(
                ctx,
                DryRun=ctx.test,
                ClientToken=name,
                **{"VpcEndpointType": vpc_endpoint_type, "VpcId": vpc_id, "ServiceName": service_name, "PolicyDocument": policy_document, "RouteTableIds": route_table_ids, "SubnetIds": subnet_ids, "SecurityGroupIds": security_group_ids, "PrivateDnsEnabled": private_dns_enabled, "TagSpecifications": tag_specifications}
            )
            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_vpc_endpoints(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, vpc_endpoint_ids: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes one or more specified VPC endpoints. You can delete any of the following types of VPC endpoints.
    Gateway endpoint,   Gateway Load Balancer endpoint,   Interface endpoint   The following rules apply when you
    delete a VPC endpoint:   When you delete a gateway endpoint, we delete the endpoint routes in the route tables
    that are associated with the endpoint.   When you delete a Gateway Load Balancer endpoint, we delete the
    endpoint network interfaces.  You can only delete Gateway Load Balancer endpoints when the routes that are
    associated with the endpoint are deleted.   When you delete an interface endpoint, we delete the endpoint
    network interfaces.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        vpc_endpoint_ids(List): One or more VPC endpoint IDs.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

