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

hub.exec.boto3.client.networkmanager.create_connection
hub.exec.boto3.client.networkmanager.delete_connection
hub.exec.boto3.client.networkmanager.get_connections
hub.exec.boto3.client.networkmanager.update_connection
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, global_network_id: Text, device_id: Text, connected_device_id: Text, link_id: Text = None, connected_link_id: Text = None, description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a connection between two devices. The devices can be a physical or virtual appliance that connects to a
    third-party appliance in a VPC, or a physical appliance that connects to another physical appliance in an on-
    premises network.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        global_network_id(Text): The ID of the global network.
        device_id(Text): The ID of the first device in the connection.
        connected_device_id(Text): The ID of the second device in the connection.
        link_id(Text, optional): The ID of the link for the first device. Defaults to None.
        connected_link_id(Text, optional): The ID of the link for the second device. Defaults to None.
        description(Text, optional): A description of the connection. Length Constraints: Maximum length of 256 characters. Defaults to None.
        tags(List, optional): The tags to apply to the resource during creation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.networkmanager.connection.present:
                - name: value
                - global_network_id: value
                - device_id: value
                - connected_device_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.networkmanager.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.networkmanager.get_connections(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.networkmanager.create_connection(
                ctx,
                
                
                **{"GlobalNetworkId": global_network_id, "DeviceId": device_id, "ConnectedDeviceId": connected_device_id, "LinkId": link_id, "ConnectedLinkId": connected_link_id, "Description": description, "Tags": tags}
            )
            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.networkmanager.get_connections(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, global_network_id: Text, connection_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified connection in your global network.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

