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

hub.exec.boto3.client.lightsail.attach_load_balancer_tls_certificate
hub.exec.boto3.client.lightsail.create_load_balancer_tls_certificate
hub.exec.boto3.client.lightsail.delete_load_balancer_tls_certificate
hub.exec.boto3.client.lightsail.get_load_balancer_tls_certificates
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, load_balancer_name: Text, certificate_name: Text, certificate_domain_name: Text, certificate_alternative_names: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an SSL/TLS certificate for an Amazon Lightsail load balancer. TLS is just an updated, more secure
    version of Secure Socket Layer (SSL). The CreateLoadBalancerTlsCertificate operation supports tag-based access
    control via resource tags applied to the resource identified by load balancer name. For more information, see
    the Amazon Lightsail Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        load_balancer_name(Text): The load balancer name where you want to create the SSL/TLS certificate.
        certificate_name(Text): The SSL/TLS certificate name. You can have up to 10 certificates in your account at one time.
            Each Lightsail load balancer can have up to 2 certificates associated with it at one time. There
            is also an overall limit to the number of certificates that can be issue in a 365-day period.
            For more information, see Limits.
        certificate_domain_name(Text): The domain name (e.g., example.com) for your SSL/TLS certificate.
        certificate_alternative_names(List, optional): An array of strings listing alternative domains and subdomains for your SSL/TLS certificate.
            Lightsail will de-dupe the names for you. You can have a maximum of 9 alternative names (in
            addition to the 1 primary domain). We do not support wildcards (e.g., *.example.com). Defaults to None.
        tags(List, optional): The tag keys and optional values to add to the resource 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.load_balancer_tls_certificate.present:
                - name: value
                - load_balancer_name: value
                - certificate_name: value
                - certificate_domain_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lightsail.load_balancer_tls_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_load_balancer_tls_certificates(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lightsail.create_load_balancer_tls_certificate(
                ctx,
                
                
                **{"loadBalancerName": load_balancer_name, "certificateName": certificate_name, "certificateDomainName": certificate_domain_name, "certificateAlternativeNames": certificate_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_load_balancer_tls_certificates(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, load_balancer_name: Text, certificate_name: Text, force: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an SSL/TLS certificate associated with a Lightsail load balancer. The DeleteLoadBalancerTlsCertificate
    operation supports tag-based access control via resource tags applied to the resource identified by load
    balancer name. For more information, see the Amazon Lightsail Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        load_balancer_name(Text): The load balancer name.
        certificate_name(Text): The SSL/TLS certificate name.
        force(bool, optional): When true, forces the deletion of an SSL/TLS certificate. There can be two certificates
            associated with a Lightsail load balancer: the primary and the backup. The force parameter is
            required when the primary SSL/TLS certificate is in use by an instance attached to the load
            balancer. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

