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

hub.exec.boto3.client.servicecatalog_appregistry.create_application
hub.exec.boto3.client.servicecatalog_appregistry.delete_application
hub.exec.boto3.client.servicecatalog_appregistry.get_application
hub.exec.boto3.client.servicecatalog_appregistry.list_applications
hub.exec.boto3.client.servicecatalog_appregistry.update_application
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, client_token: Text, description: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new application that is the top-level node in a hierarchy of related cloud resource abstractions.

    Args:
        name(Text): The name of the application. The name must be unique in the region in which you are creating the
            application.
        description(Text, optional): The description of the application. Defaults to None.
        tags(Dict, optional): Key-value pairs you can use to associate with the application. Defaults to None.
        client_token(Text): A unique identifier that you provide to ensure idempotency. If you retry a request that
            completed successfully using the same client token and the same parameters, the retry succeeds
            without performing any further actions. If you retry a successful request using the same client
            token, but one or more of the parameters are different, the retry fails.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.servicecatalog_appregistry.create_application(
                ctx,
                
                
                **{"Name": name, "description": description, "tags": tags, "clientToken": client_token}
            )
            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.servicecatalog_appregistry.get_application(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, application: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an application that is specified either by its application ID or name. All associated attribute groups
    and resources must be disassociated from it before deleting an application.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

