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

hub.exec.boto3.client.iot.create_job_template
hub.exec.boto3.client.iot.delete_job_template
hub.exec.boto3.client.iot.describe_job_template
hub.exec.boto3.client.iot.list_job_templates
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, job_template_id: Text, description: Text, job_arn: Text = None, document_source: Text = None, document: Text = None, presigned_url_config: Dict = None, job_executions_rollout_config: Dict = None, abort_config: Dict = None, timeout_config: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a job template.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        job_template_id(Text): A unique identifier for the job template. We recommend using a UUID. Alpha-numeric characters,
            "-", and "_" are valid for use here.
        job_arn(Text, optional): The ARN of the job to use as the basis for the job template. Defaults to None.
        document_source(Text, optional): An S3 link to the job document to use in the template. Required if you don't specify a value for
            document.  If the job document resides in an S3 bucket, you must use a placeholder link when
            specifying the document. The placeholder link is of the following form:  ${aws:iot:s3-presigned-
            url:https://s3.amazonaws.com/bucket/key}  where bucket is your bucket name and key is the object
            in the bucket to which you are linking. Defaults to None.
        document(Text, optional): The job document. Required if you don't specify a value for documentSource. Defaults to None.
        description(Text): A description of the job document.
        presigned_url_config(Dict, optional): Configuration for pre-signed S3 URLs. Defaults to None.
        job_executions_rollout_config(Dict, optional): Allows you to create a staged rollout of a job. Defaults to None.
        abort_config(Dict, optional): The criteria that determine when and how a job abort takes place. Defaults to None.
        timeout_config(Dict, optional): Specifies the amount of time each device has to finish its execution of the job. A timer is
            started when the job execution status is set to IN_PROGRESS. If the job execution status is not
            set to another terminal state before the timer expires, it will be automatically set to
            TIMED_OUT. Defaults to None.
        tags(List, optional): Metadata that can be used to manage the job template. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iot.job_template.present:
                - name: value
                - job_template_id: value
                - description: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.job_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_job_template(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_job_template(
                ctx,
                
                
                **{"jobTemplateId": job_template_id, "jobArn": job_arn, "documentSource": document_source, "document": document, "description": description, "presignedUrlConfig": presigned_url_config, "jobExecutionsRolloutConfig": job_executions_rollout_config, "abortConfig": abort_config, "timeoutConfig": timeout_config, "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_job_template(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, job_template_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified job template.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        job_template_id(Text): The unique identifier of the job template to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

