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

hub.exec.boto3.client.amplify.create_domain_association
hub.exec.boto3.client.amplify.delete_domain_association
hub.exec.boto3.client.amplify.get_domain_association
hub.exec.boto3.client.amplify.list_domain_associations
hub.exec.boto3.client.amplify.update_domain_association
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, app_id: Text, domain_name: Text, sub_domain_settings: List, enable_auto_sub_domain: bool = None, auto_sub_domain_creation_patterns: List = None, auto_sub_domain_iam_role: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a new domain association for an Amplify app. This action associates a custom domain with the Amplify
    app

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        app_id(Text):  The unique ID for an Amplify app.
        domain_name(Text):  The domain name for the domain association.
        enable_auto_sub_domain(bool, optional):  Enables the automated creation of subdomains for branches. Defaults to None.
        sub_domain_settings(List):  The setting for the subdomain.
        auto_sub_domain_creation_patterns(List, optional):  Sets the branch patterns for automatic subdomain creation. Defaults to None.
        auto_sub_domain_iam_role(Text, optional):  The required AWS Identity and Access Management (IAM) service role for the Amazon Resource Name
            (ARN) for automatically creating subdomains. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.amplify.domain_association.present:
                - name: value
                - app_id: value
                - domain_name: value
                - sub_domain_settings: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.amplify.domain_association.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.amplify.get_domain_association(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.amplify.create_domain_association(
                ctx,
                
                
                **{"appId": app_id, "domainName": domain_name, "enableAutoSubDomain": enable_auto_sub_domain, "subDomainSettings": sub_domain_settings, "autoSubDomainCreationPatterns": auto_sub_domain_creation_patterns, "autoSubDomainIAMRole": auto_sub_domain_iam_role}
            )
            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.amplify.get_domain_association(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, app_id: Text, domain_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes a domain association for an Amplify app.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        app_id(Text):  The unique id for an Amplify app.
        domain_name(Text):  The name of the domain.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

