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

hub.exec.boto3.client.iot.create_policy_version
hub.exec.boto3.client.iot.delete_policy_version
hub.exec.boto3.client.iot.get_policy_version
hub.exec.boto3.client.iot.list_policy_versions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, policy_name: Text, policy_document: Text, set_as_default: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new version of the specified AWS IoT policy. To update a policy, create a new policy version. A
    managed policy can have up to five versions. If the policy has five versions, you must use DeletePolicyVersion
    to delete an existing version before you create a new one. Optionally, you can set the new version as the
    policy's default version. The default version is the operative version (that is, the version that is in effect
    for the certificates to which the policy is attached).

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        policy_name(Text): The policy name.
        policy_document(Text): The JSON document that describes the policy. Minimum length of 1. Maximum length of 2048,
            excluding whitespace.
        set_as_default(bool, optional): Specifies whether the policy version is set as the default. When this parameter is true, the new
            policy version becomes the operative version (that is, the version that is in effect for the
            certificates to which the policy is attached). Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_policy_version(
                ctx,
                
                
                **{"policyName": policy_name, "policyDocument": policy_document, "setAsDefault": set_as_default}
            )
            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.get_policy_version(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, policy_name: Text, policy_version_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified version of the specified policy. You cannot delete the default version of a policy using
    this API. To delete the default version of a policy, use DeletePolicy. To find out which version of a policy is
    marked as the default version, use ListPolicyVersions.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        policy_name(Text): The name of the policy.
        policy_version_id(Text): The policy version ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

