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

hub.exec.boto3.client.connect.create_instance
hub.exec.boto3.client.connect.delete_instance
hub.exec.boto3.client.connect.describe_instance
hub.exec.boto3.client.connect.list_instances
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, identity_management_type: Text, inbound_calls_enabled: bool, outbound_calls_enabled: bool, instance_alias: Text = None, directory_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This API is in preview release for Amazon Connect and is subject to change. Initiates an Amazon Connect instance
    with all the supported channels enabled. It does not attach any storage, such as Amazon Simple Storage Service
    (Amazon S3) or Amazon Kinesis. It also does not allow for any configurations on features, such as Contact Lens
    for Amazon Connect.  Amazon Connect enforces a limit on the total number of instances that you can create or
    delete in 30 days. If you exceed this limit, you will get an error message indicating there has been an
    excessive number of attempts at creating or deleting instances. You must wait 30 days before you can restart
    creating and deleting instances in your account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        identity_management_type(Text): The type of identity management for your Amazon Connect users.
        instance_alias(Text, optional): The name for your instance. Defaults to None.
        directory_id(Text, optional): The identifier for the directory. Defaults to None.
        inbound_calls_enabled(bool): Your contact center handles incoming contacts.
        outbound_calls_enabled(bool): Your contact center allows outbound calls.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.connect.instance.present:
                - name: value
                - identity_management_type: value
                - inbound_calls_enabled: value
                - outbound_calls_enabled: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.connect.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.connect.describe_instance(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.connect.create_instance(
                ctx,
                
                ClientToken=name,
                **{"IdentityManagementType": identity_management_type, "InstanceAlias": instance_alias, "DirectoryId": directory_id, "InboundCallsEnabled": inbound_calls_enabled, "OutboundCallsEnabled": outbound_calls_enabled}
            )
            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.connect.describe_instance(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, instance_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This API is in preview release for Amazon Connect and is subject to change. Deletes the Amazon Connect instance.
    Amazon Connect enforces a limit on the total number of instances that you can create or delete in 30 days. If
    you exceed this limit, you will get an error message indicating there has been an excessive number of attempts
    at creating or deleting instances. You must wait 30 days before you can restart creating and deleting instances
    in your account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        instance_id(Text): The identifier of the Amazon Connect instance. You can find the instanceId in the ARN of the
            instance.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

