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

hub.exec.boto3.client.iot.delete_ca_certificate
hub.exec.boto3.client.iot.describe_ca_certificate
hub.exec.boto3.client.iot.list_ca_certificates
hub.exec.boto3.client.iot.register_ca_certificate
hub.exec.boto3.client.iot.update_ca_certificate
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, ca_certificate: Text, verification_certificate: Text, set_as_active: bool = None, allow_auto_registration: bool = None, registration_config: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers a CA certificate with AWS IoT. This CA certificate can then be used to sign device certificates, which
    can be then registered with AWS IoT. You can register up to 10 CA certificates per AWS account that have the
    same subject field. This enables you to have up to 10 certificate authorities sign your device certificates. If
    you have more than one CA certificate registered, make sure you pass the CA certificate when you register your
    device certificates with the RegisterCertificate API.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        ca_certificate(Text): The CA certificate.
        verification_certificate(Text): The private key verification certificate.
        set_as_active(bool, optional): A boolean value that specifies if the CA certificate is set to active. Defaults to None.
        allow_auto_registration(bool, optional): Allows this CA certificate to be used for auto registration of device certificates. Defaults to None.
        registration_config(Dict, optional): Information about the registration configuration. Defaults to None.
        tags(List, optional): Metadata which can be used to manage the CA certificate.  For URI Request parameters use format:
            ...key1=value1&key2=value2... For the CLI command-line parameter use format: &&tags
            "key1=value1&key2=value2..." For the cli-input-json file use format: "tags":
            "key1=value1&key2=value2...". Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.register_ca_certificate(
                ctx,
                
                
                **{"caCertificate": ca_certificate, "verificationCertificate": verification_certificate, "setAsActive": set_as_active, "allowAutoRegistration": allow_auto_registration, "registrationConfig": registration_config, "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.iot.describe_ca_certificate(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, certificate_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a registered CA certificate.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        certificate_id(Text): The ID of the certificate to delete. (The last part of the certificate ARN contains the
            certificate ID.).

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

