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

hub.exec.boto3.client.iot.create_provisioning_template
hub.exec.boto3.client.iot.delete_provisioning_template
hub.exec.boto3.client.iot.describe_provisioning_template
hub.exec.boto3.client.iot.list_provisioning_templates
hub.exec.boto3.client.iot.update_provisioning_template
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, template_name: Text, template_body: Text, provisioning_role_arn: Text, description: Text = None, enabled: bool = None, pre_provisioning_hook: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a fleet provisioning template.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        template_name(Text): The name of the fleet provisioning template.
        description(Text, optional): The description of the fleet provisioning template. Defaults to None.
        template_body(Text): The JSON formatted contents of the fleet provisioning template.
        enabled(bool, optional): True to enable the fleet provisioning template, otherwise false. Defaults to None.
        provisioning_role_arn(Text): The role ARN for the role associated with the fleet provisioning template. This IoT role grants
            permission to provision a device.
        pre_provisioning_hook(Dict, optional): Creates a pre-provisioning hook template. Defaults to None.
        tags(List, optional): Metadata which can be used to manage the fleet provisioning template.  For URI Request
            parameters use format: ...key1=value1&key2=value2... For the CLI command-line parameter use
            format: &&tags "key1=value1&key2=value2..." For the cli-input-json file use format: "tags":
            "key1=value1&key2=value2...". Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iot.provisioning_template.present:
                - name: value
                - template_name: value
                - template_body: value
                - provisioning_role_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.provisioning_template.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.describe_provisioning_template(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_provisioning_template(
                ctx,
                
                
                **{"templateName": template_name, "description": description, "templateBody": template_body, "enabled": enabled, "provisioningRoleArn": provisioning_role_arn, "preProvisioningHook": pre_provisioning_hook, "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.iot.describe_provisioning_template(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, template_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a fleet provisioning template.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        template_name(Text): The name of the fleet provision template to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

