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

hub.exec.boto3.client.directconnect.create_interconnect
hub.exec.boto3.client.directconnect.delete_interconnect
hub.exec.boto3.client.directconnect.describe_interconnects
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, interconnect_name: Text, bandwidth: Text, location: Text, lag_id: Text = None, tags: List = None, provider_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an interconnect between an Direct Connect Partner's network and a specific Direct Connect location. An
    interconnect is a connection that is capable of hosting other connections. The Direct Connect Partner can use an
    interconnect to provide Direct Connect hosted connections to customers through their own network services. Like
    a standard connection, an interconnect links the partner's network to an Direct Connect location over a standard
    Ethernet fiber-optic cable. One end is connected to the partner's router, the other to an Direct Connect router.
    You can automatically add the new interconnect to a link aggregation group (LAG) by specifying a LAG ID in the
    request. This ensures that the new interconnect 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 interconnect is
    created. For each end customer, the Direct Connect Partner provisions a connection on their interconnect by
    calling AllocateHostedConnection. The end customer can then connect to Amazon Web Services resources by creating
    a virtual interface on their connection, using the VLAN assigned to them by the Direct Connect Partner.
    Intended for use by Direct Connect Partners only.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        interconnect_name(Text): The name of the interconnect.
        bandwidth(Text): The port bandwidth, in Gbps. The possible values are 1 and 10.
        location(Text): The location of the interconnect.
        lag_id(Text, optional): The ID of the LAG. Defaults to None.
        tags(List, optional): The tags to associate with the interconnect. Defaults to None.
        provider_name(Text, optional): The name of the service provider associated with the interconnect. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, interconnect_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified interconnect.  Intended for use by Direct Connect Partners only.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

