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

hub.exec.boto3.client.cognito_idp.create_user_pool_domain
hub.exec.boto3.client.cognito_idp.delete_user_pool_domain
hub.exec.boto3.client.cognito_idp.describe_user_pool_domain
hub.exec.boto3.client.cognito_idp.update_user_pool_domain
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain: Text, user_pool_id: Text, custom_domain_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new domain for a user pool.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain(Text): The domain string.
        user_pool_id(Text): The user pool ID.
        custom_domain_config(Dict, optional): The configuration for a custom domain that hosts the sign-up and sign-in webpages for your
            application. Provide this parameter only if you want to use a custom domain for your user pool.
            Otherwise, you can exclude this parameter and use the Amazon Cognito hosted domain instead. For
            more information about the hosted domain and custom domains, see Configuring a User Pool Domain. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cognito_idp.user_pool_domain.present:
                - name: value
                - domain: value
                - user_pool_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cognito_idp.user_pool_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.cognito_idp.describe_user_pool_domain(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cognito_idp.create_user_pool_domain(
                ctx,
                
                
                **{"Domain": domain, "UserPoolId": user_pool_id, "CustomDomainConfig": custom_domain_config}
            )
            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.cognito_idp.describe_user_pool_domain(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, domain: Text, user_pool_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a domain for a user pool.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain(Text): The domain string.
        user_pool_id(Text): The user pool ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

