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

hub.exec.boto3.client.cloudhsm.create_hapg
hub.exec.boto3.client.cloudhsm.delete_hapg
hub.exec.boto3.client.cloudhsm.describe_hapg
hub.exec.boto3.client.cloudhsm.list_hapgs
hub.exec.boto3.client.cloudhsm.modify_hapg
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, label: 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.
    Creates a high-availability partition group. A high-availability partition group is a group of partitions that
    spans multiple physical HSMs.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        label(Text): The label of the new high-availability partition group.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudhsm.hapg.present:
                - name: value
                - label: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudhsm.hapg.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_hapg(name)

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

async def absent(hub, ctx, name: Text, hapg_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 a high-availability partition group.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        hapg_arn(Text): The ARN of the high-availability partition group to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

