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

hub.exec.boto3.client.apigateway.create_domain_name
hub.exec.boto3.client.apigateway.delete_domain_name
hub.exec.boto3.client.apigateway.get_domain_names
hub.exec.boto3.client.apigateway.update_domain_name
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain_name: Text, certificate_name: Text = None, certificate_body: Text = None, certificate_private_key: Text = None, certificate_chain: Text = None, certificate_arn: Text = None, regional_certificate_name: Text = None, regional_certificate_arn: Text = None, endpoint_configuration: Dict = None, tags: Dict = None, security_policy: Text = None, mutual_tls_authentication: Dict = None, ownership_verification_certificate_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new domain name.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): [Required] The name of the DomainName resource.
        certificate_name(Text, optional): The user-friendly name of the certificate that will be used by edge-optimized endpoint for this
            domain name. Defaults to None.
        certificate_body(Text, optional): [Deprecated] The body of the server certificate that will be used by edge-optimized endpoint for
            this domain name provided by your certificate authority. Defaults to None.
        certificate_private_key(Text, optional): [Deprecated] Your edge-optimized endpoint's domain name certificate's private key. Defaults to None.
        certificate_chain(Text, optional): [Deprecated] The intermediate certificates and optionally the root certificate, one after the
            other without any blank lines, used by an edge-optimized endpoint for this domain name. If you
            include the root certificate, your certificate chain must start with intermediate certificates
            and end with the root certificate. Use the intermediate certificates that were provided by your
            certificate authority. Do not include any intermediaries that are not in the chain of trust
            path. Defaults to None.
        certificate_arn(Text, optional): The reference to an AWS-managed certificate that will be used by edge-optimized endpoint for
            this domain name. AWS Certificate Manager is the only supported source. Defaults to None.
        regional_certificate_name(Text, optional): The user-friendly name of the certificate that will be used by regional endpoint for this domain
            name. Defaults to None.
        regional_certificate_arn(Text, optional): The reference to an AWS-managed certificate that will be used by regional endpoint for this
            domain name. AWS Certificate Manager is the only supported source. Defaults to None.
        endpoint_configuration(Dict, optional): The endpoint configuration of this DomainName showing the endpoint types of the domain name. Defaults to None.
        tags(Dict, optional): The key-value map of strings. The valid character set is [a-zA-Z+-=._:/]. The tag key can be up
            to 128 characters and must not start with aws:. The tag value can be up to 256 characters. Defaults to None.
        security_policy(Text, optional): The Transport Layer Security (TLS) version + cipher suite for this DomainName. The valid values
            are TLS_1_0 and TLS_1_2. Defaults to None.
        mutual_tls_authentication(Dict, optional): If specified, API Gateway performs two-way authentication between the client and the server.
            Clients must present a trusted certificate to access your custom domain name. Defaults to None.
        ownership_verification_certificate_arn(Text, optional): The ARN of the public certificate issued by ACM to validate ownership of your custom domain.
            Only required when configuring mutual TLS and using an ACM imported or private CA certificate
            ARN as the regionalCertificateArn. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.create_domain_name(
                ctx,
                
                
                **{"domainName": domain_name, "certificateName": certificate_name, "certificateBody": certificate_body, "certificatePrivateKey": certificate_private_key, "certificateChain": certificate_chain, "certificateArn": certificate_arn, "regionalCertificateName": regional_certificate_name, "regionalCertificateArn": regional_certificate_arn, "endpointConfiguration": endpoint_configuration, "tags": tags, "securityPolicy": security_policy, "mutualTlsAuthentication": mutual_tls_authentication, "ownershipVerificationCertificateArn": ownership_verification_certificate_arn}
            )
            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.apigateway.get_domain_names(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 the DomainName resource.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): [Required] The name of the DomainName resource to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

