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

hub.exec.boto3.client.directconnect.associate_virtual_interface
hub.exec.boto3.client.directconnect.delete_virtual_interface
hub.exec.boto3.client.directconnect.describe_virtual_interfaces
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, virtual_interface_id: Text, connection_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Associates a virtual interface with a specified link aggregation group (LAG) or connection. Connectivity to
    Amazon Web Services is temporarily interrupted as the virtual interface is being migrated. If the target
    connection or LAG has an associated virtual interface with a conflicting VLAN number or a conflicting IP
    address, the operation fails. Virtual interfaces associated with a hosted connection cannot be associated with a
    LAG; hosted connections must be migrated along with their virtual interfaces using AssociateHostedConnection. To
    reassociate a virtual interface to a new connection or LAG, the requester must own either the virtual interface
    itself or the connection to which the virtual interface is currently associated. Additionally, the requester
    must own the connection or LAG for the association.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, virtual_interface_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a virtual interface.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

