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

hub.exec.boto3.client.directconnect.create_direct_connect_gateway_association
hub.exec.boto3.client.directconnect.delete_direct_connect_gateway_association
hub.exec.boto3.client.directconnect.describe_direct_connect_gateway_associations
hub.exec.boto3.client.directconnect.update_direct_connect_gateway_association
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, direct_connect_gateway_id: Text, gateway_id: Text = None, add_allowed_prefixes_to_direct_connect_gateway: List = None, virtual_gateway_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an association between a Direct Connect gateway and a virtual private gateway. The virtual private
    gateway must be attached to a VPC and must not be associated with another Direct Connect gateway.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        direct_connect_gateway_id(Text): The ID of the Direct Connect gateway.
        gateway_id(Text, optional): The ID of the virtual private gateway or transit gateway. Defaults to None.
        add_allowed_prefixes_to_direct_connect_gateway(List, optional): The Amazon VPC prefixes to advertise to the Direct Connect gateway This parameter is required
            when you create an association to a transit gateway. For information about how to set the
            prefixes, see Allowed Prefixes in the Direct Connect User Guide. Defaults to None.
        virtual_gateway_id(Text, optional): The ID of the virtual private gateway. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.directconnect.create_direct_connect_gateway_association(
                ctx,
                
                
                **{"directConnectGatewayId": direct_connect_gateway_id, "gatewayId": gateway_id, "addAllowedPrefixesToDirectConnectGateway": add_allowed_prefixes_to_direct_connect_gateway, "virtualGatewayId": virtual_gateway_id}
            )
            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_direct_connect_gateway_associations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, association_id: Text = None, direct_connect_gateway_id: Text = None, virtual_gateway_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the association between the specified Direct Connect gateway and virtual private gateway. We recommend
    that you specify the associationID to delete the association. Alternatively, if you own virtual gateway and a
    Direct Connect gateway association, you can specify the virtualGatewayId and directConnectGatewayId to delete an
    association.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        association_id(Text, optional): The ID of the Direct Connect gateway association. Defaults to None.
        direct_connect_gateway_id(Text, optional): The ID of the Direct Connect gateway. Defaults to None.
        virtual_gateway_id(Text, optional): The ID of the virtual private gateway. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.directconnect.delete_direct_connect_gateway_association(
                ctx,
                
                
                **{"associationId": association_id, "directConnectGatewayId": direct_connect_gateway_id, "virtualGatewayId": virtual_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.directconnect.describe_direct_connect_gateway_associations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

