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

hub.exec.boto3.client.iotfleethub.create_application
hub.exec.boto3.client.iotfleethub.delete_application
hub.exec.boto3.client.iotfleethub.describe_application
hub.exec.boto3.client.iotfleethub.list_applications
hub.exec.boto3.client.iotfleethub.update_application
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, application_name: Text, role_arn: Text, application_description: Text = None, client_token: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Fleet Hub for AWS IoT Device Management web application.  Fleet Hub for AWS IoT Device Management is
    in public preview and is subject to change.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        application_name(Text): The name of the web application.
        application_description(Text, optional): An optional description of the web application. Defaults to None.
        client_token(Text, optional): A unique case-sensitive identifier that you can provide to ensure the idempotency of the
            request. Don't reuse this client token if a new idempotent request is required. Defaults to None.
        role_arn(Text): The ARN of the role that the web application assumes when it interacts with AWS IoT Core.  The
            name of the role must be in the form AWSIotFleetHub_random_string .
        tags(Dict, optional): A set of key/value pairs that you can use to manage the web application resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotfleethub.create_application(
                ctx,
                
                
                **{"applicationName": application_name, "applicationDescription": application_description, "clientToken": client_token, "roleArn": role_arn, "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.iotfleethub.describe_application(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, application_id: Text, client_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a Fleet Hub for AWS IoT Device Management web application.  Fleet Hub for AWS IoT Device Management is
    in public preview and is subject to change.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        application_id(Text): The unique Id of the web application.
        client_token(Text, optional): A unique case-sensitive identifier that you can provide to ensure the idempotency of the
            request. Don't reuse this client token if a new idempotent request is required. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

