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

hub.exec.boto3.client.redshift.create_hsm_client_certificate
hub.exec.boto3.client.redshift.delete_hsm_client_certificate
hub.exec.boto3.client.redshift.describe_hsm_client_certificates
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, hsm_client_certificate_identifier: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an HSM client certificate that an Amazon Redshift cluster will use to connect to the client's HSM in
    order to store and retrieve the keys used to encrypt the cluster databases. The command returns a public key,
    which you must store in the HSM. In addition to creating the HSM certificate, you must create an Amazon Redshift
    HSM configuration that provides a cluster the information needed to store and use encryption keys in the HSM.
    For more information, go to Hardware Security Modules in the Amazon Redshift Cluster Management Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        hsm_client_certificate_identifier(Text): The identifier to be assigned to the new HSM client certificate that the cluster will use to
            connect to the HSM to use the database encryption keys.
        tags(List, optional): A list of tag instances. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.create_hsm_client_certificate(
                ctx,
                
                
                **{"HsmClientCertificateIdentifier": hsm_client_certificate_identifier, "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.redshift.describe_hsm_client_certificates(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, hsm_client_certificate_identifier: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified HSM client certificate.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        hsm_client_certificate_identifier(Text): The identifier of the HSM client certificate to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

