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

hub.exec.boto3.client.redshift.create_hsm_configuration
hub.exec.boto3.client.redshift.delete_hsm_configuration
hub.exec.boto3.client.redshift.describe_hsm_configurations
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, hsm_configuration_identifier: Text, description: Text, hsm_ip_address: Text, hsm_partition_name: Text, hsm_partition_password: Text, hsm_server_public_certificate: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an HSM configuration that contains the information required by an Amazon Redshift cluster to store and
    use database encryption keys in a Hardware Security Module (HSM). After creating the HSM configuration, you can
    specify it as a parameter when creating a cluster. The cluster will then store its encryption keys in the HSM.
    In addition to creating an HSM configuration, you must also create an HSM client certificate. 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_configuration_identifier(Text): The identifier to be assigned to the new Amazon Redshift HSM configuration.
        description(Text): A text description of the HSM configuration to be created.
        hsm_ip_address(Text): The IP address that the Amazon Redshift cluster must use to access the HSM.
        hsm_partition_name(Text): The name of the partition in the HSM where the Amazon Redshift clusters will store their
            database encryption keys.
        hsm_partition_password(Text): The password required to access the HSM partition.
        hsm_server_public_certificate(Text): The HSMs public certificate file. When using Cloud HSM, the file name is server.pem.
        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_configuration.present:
                - name: value
                - hsm_configuration_identifier: value
                - description: value
                - hsm_ip_address: value
                - hsm_partition_name: value
                - hsm_partition_password: value
                - hsm_server_public_certificate: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.hsm_configuration.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_configurations(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.create_hsm_configuration(
                ctx,
                
                
                **{"HsmConfigurationIdentifier": hsm_configuration_identifier, "Description": description, "HsmIpAddress": hsm_ip_address, "HsmPartitionName": hsm_partition_name, "HsmPartitionPassword": hsm_partition_password, "HsmServerPublicCertificate": hsm_server_public_certificate, "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_configurations(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        hsm_configuration_identifier(Text): The identifier of the Amazon Redshift HSM configuration to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

