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

hub.exec.boto3.client.chime_sdk_identity.create_app_instance
hub.exec.boto3.client.chime_sdk_identity.delete_app_instance
hub.exec.boto3.client.chime_sdk_identity.describe_app_instance
hub.exec.boto3.client.chime_sdk_identity.list_app_instances
hub.exec.boto3.client.chime_sdk_identity.update_app_instance
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, client_request_token: Text, metadata: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon Chime SDK messaging AppInstance under an AWS account. Only SDK messaging customers use this
    API. CreateAppInstance supports idempotency behavior as described in the AWS API Standard. identity

    Args:
        name(Text): The name of the AppInstance.
        metadata(Text, optional): The metadata of the AppInstance. Limited to a 1KB string in UTF-8. Defaults to None.
        client_request_token(Text): The ClientRequestToken of the AppInstance.
        tags(List, optional): Tags assigned to the AppInstanceUser. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.chime_sdk_identity.create_app_instance(
                ctx,
                
                
                **{"Name": name, "Metadata": metadata, "ClientRequestToken": client_request_token, "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.chime_sdk_identity.describe_app_instance(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, app_instance_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an AppInstance and all associated data asynchronously.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

