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

hub.exec.boto3.client.batch.deregister_job_definition
hub.exec.boto3.client.batch.describe_job_definitions
hub.exec.boto3.client.batch.register_job_definition
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, job_definition_name: Text, type_: Text, parameters: Dict = None, container_properties: Dict = None, node_properties: Dict = None, retry_strategy: Dict = None, propagate_tags: bool = None, timeout: Dict = None, tags: Dict = None, platform_capabilities: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers an Batch job definition.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        job_definition_name(Text): The name of the job definition to register. Up to 128 letters (uppercase and lowercase),
            numbers, hyphens, and underscores are allowed.
        type_(Text): The type of job definition. For more information about multi-node parallel jobs, see Creating a
            multi-node parallel job definition in the Batch User Guide.  If the job is run on Fargate
            resources, then multinode isn't supported.
        parameters(Dict, optional): Default parameter substitution placeholders to set in the job definition. Parameters are
            specified as a key-value pair mapping. Parameters in a SubmitJob request override any
            corresponding parameter defaults from the job definition. Defaults to None.
        container_properties(Dict, optional): An object with various properties specific to single-node container-based jobs. If the job
            definition's type parameter is container, then you must specify either containerProperties or
            nodeProperties.  If the job runs on Fargate resources, then you must not specify nodeProperties;
            use only containerProperties. Defaults to None.
        node_properties(Dict, optional): An object with various properties specific to multi-node parallel jobs. If you specify node
            properties for a job, it becomes a multi-node parallel job. For more information, see Multi-node
            Parallel Jobs in the Batch User Guide. If the job definition's type parameter is container, then
            you must specify either containerProperties or nodeProperties.  If the job runs on Fargate
            resources, then you must not specify nodeProperties; use containerProperties instead. Defaults to None.
        retry_strategy(Dict, optional): The retry strategy to use for failed jobs that are submitted with this job definition. Any retry
            strategy that's specified during a SubmitJob operation overrides the retry strategy defined
            here. If a job is terminated due to a timeout, it isn't retried. Defaults to None.
        propagate_tags(bool, optional): Specifies whether to propagate the tags from the job or job definition to the corresponding
            Amazon ECS task. If no value is specified, the tags are not propagated. Tags can only be
            propagated to the tasks during task creation. For tags with the same name, job tags are given
            priority over job definitions tags. If the total number of combined tags from the job and job
            definition is over 50, the job is moved to the FAILED state. Defaults to None.
        timeout(Dict, optional): The timeout configuration for jobs that are submitted with this job definition, after which
            Batch terminates your jobs if they have not finished. If a job is terminated due to a timeout,
            it isn't retried. The minimum value for the timeout is 60 seconds. Any timeout configuration
            that's specified during a SubmitJob operation overrides the timeout configuration defined here.
            For more information, see Job Timeouts in the Batch User Guide. Defaults to None.
        tags(Dict, optional): The tags that you apply to the job definition to help you categorize and organize your
            resources. Each tag consists of a key and an optional value. For more information, see Tagging
            Amazon Web Services Resources in Batch User Guide. Defaults to None.
        platform_capabilities(List, optional): The platform capabilities required by the job definition. If no value is specified, it defaults
            to EC2. To run the job on Fargate resources, specify FARGATE. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.batch.job_definition.present:
                - name: value
                - job_definition_name: value
                - type_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.batch.job_definition.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.batch.describe_job_definitions(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.batch.register_job_definition(
                ctx,
                
                
                **{"jobDefinitionName": job_definition_name, "type": type_, "parameters": parameters, "containerProperties": container_properties, "nodeProperties": node_properties, "retryStrategy": retry_strategy, "propagateTags": propagate_tags, "timeout": timeout, "tags": tags, "platformCapabilities": platform_capabilities}
            )
            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.batch.describe_job_definitions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, job_definition: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deregisters an Batch job definition. Job definitions are permanently deleted after 180 days.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        job_definition(Text): The name and revision (name:revision) or full Amazon Resource Name (ARN) of the job definition
            to deregister.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

