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

hub.exec.boto3.client.apprunner.create_connection
hub.exec.boto3.client.apprunner.delete_connection
hub.exec.boto3.client.apprunner.list_connections
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, connection_name: Text, provider_type: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create an AWS App Runner connection resource. App Runner requires a connection resource when you create App
    Runner services that access private repositories from certain third-party providers. You can share a connection
    across multiple services. A connection resource is needed to access GitHub repositories. GitHub requires a user
    interface approval process through the App Runner console before you can use the connection.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        connection_name(Text): A name for the new connection. It must be unique across all App Runner connections for the AWS
            account in the AWS Region.
        provider_type(Text): The source repository provider.
        tags(List, optional): A list of metadata items that you can associate with your connection resource. A tag is a key-
            value pair. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apprunner.create_connection(
                ctx,
                
                
                **{"ConnectionName": connection_name, "ProviderType": provider_type, "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.apprunner.list_connections(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**
    
    Delete an AWS App Runner connection. You must first ensure that there are no running App Runner services that
    use this connection. If there are any, the DeleteConnection action fails.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        connection_arn(Text): The Amazon Resource Name (ARN) of the App Runner connection that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

