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

hub.exec.boto3.client.cloudhsm.create_hsm
hub.exec.boto3.client.cloudhsm.delete_hsm
hub.exec.boto3.client.cloudhsm.describe_hsm
hub.exec.boto3.client.cloudhsm.list_hsms
hub.exec.boto3.client.cloudhsm.modify_hsm
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, subnet_id: Text, ssh_key: Text, iam_role_arn: Text, subscription_type: Text, eni_ip: Text = None, external_id: Text = None, syslog_ip: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This is documentation for AWS CloudHSM Classic. For more information, see AWS CloudHSM Classic FAQs, the AWS
    CloudHSM Classic User Guide, and the AWS CloudHSM Classic API Reference.  For information about the current
    version of AWS CloudHSM, see AWS CloudHSM, the AWS CloudHSM User Guide, and the AWS CloudHSM API Reference.
    Creates an uninitialized HSM instance. There is an upfront fee charged for each HSM instance that you create
    with the CreateHsm operation. If you accidentally provision an HSM and want to request a refund, delete the
    instance using the DeleteHsm operation, go to the AWS Support Center, create a new case, and select Account and
    Billing Support.  It can take up to 20 minutes to create and provision an HSM. You can monitor the status of the
    HSM with the DescribeHsm operation. The HSM is ready to be initialized when the status changes to RUNNING.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        subnet_id(Text): The identifier of the subnet in your VPC in which to place the HSM.
        ssh_key(Text): The SSH public key to install on the HSM.
        eni_ip(Text, optional): The IP address to assign to the HSM's ENI. If an IP address is not specified, an IP address will
            be randomly chosen from the CIDR range of the subnet. Defaults to None.
        iam_role_arn(Text): The ARN of an IAM role to enable the AWS CloudHSM service to allocate an ENI on your behalf.
        external_id(Text, optional): The external ID from IamRoleArn, if present. Defaults to None.
        subscription_type(Text): Specifies the type of subscription for the HSM.    PRODUCTION - The HSM is being used in a
            production environment.    TRIAL - The HSM is being used in a product trial.
        syslog_ip(Text, optional): The IP address for the syslog monitoring server. The AWS CloudHSM service only supports one
            syslog monitoring server. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudhsm.hsm.present:
                - name: value
                - subnet_id: value
                - ssh_key: value
                - iam_role_arn: value
                - subscription_type: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudhsm.hsm.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.cloudhsm.describe_hsm(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudhsm.create_hsm(
                ctx,
                
                ClientToken=name,
                **{"SubnetId": subnet_id, "SshKey": ssh_key, "EniIp": eni_ip, "IamRoleArn": iam_role_arn, "ExternalId": external_id, "SubscriptionType": subscription_type, "SyslogIp": syslog_ip}
            )
            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.cloudhsm.describe_hsm(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, hsm_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This is documentation for AWS CloudHSM Classic. For more information, see AWS CloudHSM Classic FAQs, the AWS
    CloudHSM Classic User Guide, and the AWS CloudHSM Classic API Reference.  For information about the current
    version of AWS CloudHSM, see AWS CloudHSM, the AWS CloudHSM User Guide, and the AWS CloudHSM API Reference.
    Deletes an HSM. After completion, this operation cannot be undone and your key material cannot be recovered.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        hsm_arn(Text): The ARN of the HSM to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

