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

hub.exec.boto3.client.customer_profiles.create_domain
hub.exec.boto3.client.customer_profiles.delete_domain
hub.exec.boto3.client.customer_profiles.get_domain
hub.exec.boto3.client.customer_profiles.list_domains
hub.exec.boto3.client.customer_profiles.update_domain
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain_name: Text, default_expiration_days: int, default_encryption_key: Text = None, dead_letter_queue_url: Text = None, matching: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a domain, which is a container for all customer data, such as customer profile attributes, object types,
    profile keys, and encryption keys. You can create multiple domains, and each domain can have multiple third-
    party integrations. Each Amazon Connect instance can be associated with only one domain. Multiple Amazon Connect
    instances can be associated with one domain. Use this API or UpdateDomain to enable identity resolution: set
    Matching to true.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): The unique name of the domain.
        default_expiration_days(int): The default number of days until the data within the domain expires.
        default_encryption_key(Text, optional): The default encryption key, which is an AWS managed key, is used when no specific type of
            encryption key is specified. It is used to encrypt all data before it is placed in permanent or
            semi-permanent storage. Defaults to None.
        dead_letter_queue_url(Text, optional): The URL of the SQS dead letter queue, which is used for reporting errors associated with
            ingesting data from third party applications. You must set up a policy on the DeadLetterQueue
            for the SendMessage operation to enable Amazon Connect Customer Profiles to send messages to the
            DeadLetterQueue. Defaults to None.
        matching(Dict, optional): The process of matching duplicate profiles. If Matching = true, Amazon Connect Customer Profiles
            starts a weekly batch process every Saturday at 12AM UTC to detect duplicate profiles in your
            domains. After that batch process completes, use the GetMatches API to return and review the
            results. Defaults to None.
        tags(Dict, optional): The tags used to organize, track, or control access for this resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.customer_profiles.domain.present:
                - name: value
                - domain_name: value
                - default_expiration_days: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.customer_profiles.domain.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.customer_profiles.get_domain(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.customer_profiles.create_domain(
                ctx,
                
                
                **{"DomainName": domain_name, "DefaultExpirationDays": default_expiration_days, "DefaultEncryptionKey": default_encryption_key, "DeadLetterQueueUrl": dead_letter_queue_url, "Matching": matching, "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.customer_profiles.get_domain(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, domain_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a specific domain and all of its customer data, such as customer profile attributes and their related
    objects.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

