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

hub.exec.boto3.client.imagebuilder.create_image_recipe
hub.exec.boto3.client.imagebuilder.delete_image_recipe
hub.exec.boto3.client.imagebuilder.get_image_recipe
hub.exec.boto3.client.imagebuilder.list_image_recipes
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, semantic_version: Text, components: List, parent_image: Text, client_token: Text, description: Text = None, block_device_mappings: List = None, tags: Dict = None, working_directory: Text = None, additional_instance_configuration: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a new image recipe. Image recipes define how images are configured, tested, and assessed.

    Args:
        name(Text):  The name of the image recipe.
        description(Text, optional):  The description of the image recipe. Defaults to None.
        semantic_version(Text): The semantic version of the image recipe. This version follows the semantic version syntax.  The
            semantic version has four nodes: <major>.<minor>.<patch>/<build>. You can assign values for the
            first three, and can filter on all of them.  Assignment: For the first three nodes you can
            assign any positive integer value, including zero, with an upper limit of 2^30-1, or 1073741823
            for each node. Image Builder automatically assigns the build number, and that is not open for
            updates.  Patterns: You can use any numeric pattern that adheres to the assignment requirements
            for the nodes that you can assign. For example, you might choose a software version pattern,
            such as 1.0.0, or a date, such as 2021.01.01.
        components(List): The components of the image recipe.
        parent_image(Text): The parent image of the image recipe. The value of the string can be the ARN of the parent image
            or an AMI ID. The format for the ARN follows this example: arn:aws:imagebuilder:us-
            west-2:aws:image/windows-server-2016-english-full-base-x86/x.x.x. You can provide the specific
            version that you want to use, or you can use a wildcard in all of the fields. If you enter an
            AMI ID for the string value, you must have access to the AMI, and the AMI must be in the same
            Region in which you are using Image Builder.
        block_device_mappings(List, optional): The block device mappings of the image recipe. Defaults to None.
        tags(Dict, optional):  The tags of the image recipe. Defaults to None.
        working_directory(Text, optional): The working directory used during build and test workflows. Defaults to None.
        additional_instance_configuration(Dict, optional): Specify additional settings and launch scripts for your build instances. Defaults to None.
        client_token(Text): The idempotency token used to make this request idempotent.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.imagebuilder.image_recipe.present:
                - name: value
                - semantic_version: value
                - components: value
                - parent_image: value
                - client_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.imagebuilder.image_recipe.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.imagebuilder.get_image_recipe(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.imagebuilder.create_image_recipe(
                ctx,
                
                
                **{"Name": name, "description": description, "semanticVersion": semantic_version, "components": components, "parentImage": parent_image, "blockDeviceMappings": block_device_mappings, "tags": tags, "workingDirectory": working_directory, "additionalInstanceConfiguration": additional_instance_configuration, "clientToken": client_token}
            )
            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.imagebuilder.get_image_recipe(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, image_recipe_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes an image recipe.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        image_recipe_arn(Text): The Amazon Resource Name (ARN) of the image recipe to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

