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

hub.exec.boto3.client.codestar_connections.create_connection
hub.exec.boto3.client.codestar_connections.delete_connection
hub.exec.boto3.client.codestar_connections.get_connection
hub.exec.boto3.client.codestar_connections.list_connections
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, connection_name: Text, provider_type: Text = None, tags: List = None, host_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a connection that can then be given to other AWS services like CodePipeline so that it can access third-
    party code repositories. The connection is in pending status until the third-party connection handshake is
    completed from the console.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        provider_type(Text, optional): The name of the external provider where your third-party code repository is configured. Defaults to None.
        connection_name(Text): The name of the connection to be created. The name must be unique in the calling AWS account.
        tags(List, optional): The key-value pair to use when tagging the resource. Defaults to None.
        host_arn(Text, optional): The Amazon Resource Name (ARN) of the host associated with the connection to be created. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codestar_connections.create_connection(
                ctx,
                
                
                **{"ProviderType": provider_type, "ConnectionName": connection_name, "Tags": tags, "HostArn": host_arn}
            )
            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.codestar_connections.get_connection(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, connection_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    The connection to be deleted.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        connection_arn(Text): The Amazon Resource Name (ARN) of the connection to be deleted.  The ARN is never reused if the
            connection is deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

