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

hub.exec.boto3.client.directconnect.confirm_connection
hub.exec.boto3.client.directconnect.create_connection
hub.exec.boto3.client.directconnect.delete_connection
hub.exec.boto3.client.directconnect.describe_connections
hub.exec.boto3.client.directconnect.update_connection
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, location: Text, bandwidth: Text, connection_name: Text, lag_id: Text = None, tags: List = None, provider_name: Text = None, request_mac_sec: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a connection between a customer network and a specific Direct Connect location. A connection links your
    internal network to an Direct Connect location over a standard Ethernet fiber-optic cable. One end of the cable
    is connected to your router, the other to an Direct Connect router. To find the locations for your Region, use
    DescribeLocations. You can automatically add the new connection to a link aggregation group (LAG) by specifying
    a LAG ID in the request. This ensures that the new connection is allocated on the same Direct Connect endpoint
    that hosts the specified LAG. If there are no available ports on the endpoint, the request fails and no
    connection is created.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        location(Text): The location of the connection.
        bandwidth(Text): The bandwidth of the connection.
        connection_name(Text): The name of the connection.
        lag_id(Text, optional): The ID of the LAG. Defaults to None.
        tags(List, optional): The tags to associate with the lag. Defaults to None.
        provider_name(Text, optional): The name of the service provider associated with the requested connection. Defaults to None.
        request_mac_sec(bool, optional): Indicates whether you want the connection to support MAC Security (MACsec). MAC Security
            (MACsec) is only available on dedicated connections. For information about MAC Security (MACsec)
            prerequisties, see MACsec prerequisties in the Direct Connect User Guide. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.directconnect.connection.present:
                - name: value
                - location: value
                - bandwidth: value
                - connection_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.directconnect.connection.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.directconnect.describe_connections(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.directconnect.create_connection(
                ctx,
                
                
                **{"location": location, "bandwidth": bandwidth, "connectionName": connection_name, "lagId": lag_id, "tags": tags, "providerName": provider_name, "requestMACSec": request_mac_sec}
            )
            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.directconnect.describe_connections(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, connection_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified connection. Deleting a connection only stops the Direct Connect port hour and data
    transfer charges. If you are partnering with any third parties to connect with the Direct Connect location, you
    must cancel your service with them separately.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

