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

hub.exec.boto3.client.lightsail.create_certificate
hub.exec.boto3.client.lightsail.delete_certificate
hub.exec.boto3.client.lightsail.get_certificates
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, certificate_name: Text, domain_name: Text, subject_alternative_names: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an SSL/TLS certificate for an Amazon Lightsail content delivery network (CDN) distribution and a
    container service. After the certificate is valid, use the AttachCertificateToDistribution action to use the
    certificate and its domains with your distribution. Or use the UpdateContainerService action to use the
    certificate and its domains with your container service.  Only certificates created in the us-east-1 AWS Region
    can be attached to Lightsail distributions. Lightsail distributions are global resources that can reference an
    origin in any AWS Region, and distribute its content globally. However, all distributions are located in the us-
    east-1 Region.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        certificate_name(Text): The name for the certificate.
        domain_name(Text): The domain name (e.g., example.com) for the certificate.
        subject_alternative_names(List, optional): An array of strings that specify the alternate domains (e.g., example2.com) and subdomains
            (e.g., blog.example.com) for the certificate. You can specify a maximum of nine alternate
            domains (in addition to the primary domain name). Wildcard domain entries (e.g., *.example.com)
            are not supported. Defaults to None.
        tags(List, optional): The tag keys and optional values to add to the certificate during create. Use the TagResource
            action to tag a resource after it's created. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lightsail.create_certificate(
                ctx,
                
                
                **{"certificateName": certificate_name, "domainName": domain_name, "subjectAlternativeNames": subject_alternative_names, "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.lightsail.get_certificates(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, certificate_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an SSL/TLS certificate for your Amazon Lightsail content delivery network (CDN) distribution.
    Certificates that are currently attached to a distribution cannot be deleted. Use the
    DetachCertificateFromDistribution action to detach a certificate from a distribution.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        certificate_name(Text): The name of the certificate to delete. Use the GetCertificates action to get a list of
            certificate names that you can specify.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

