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

hub.exec.boto3.client.imagebuilder.create_image
hub.exec.boto3.client.imagebuilder.delete_image
hub.exec.boto3.client.imagebuilder.get_image
hub.exec.boto3.client.imagebuilder.list_images
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, infrastructure_configuration_arn: Text, client_token: Text, image_recipe_arn: Text = None, container_recipe_arn: Text = None, distribution_configuration_arn: Text = None, image_tests_configuration: Dict = None, enhanced_image_metadata_enabled: bool = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a new image. This request will create a new image along with all of the configured output resources
    defined in the distribution configuration. You must specify exactly one recipe for your image, using either a
    ContainerRecipeArn or an ImageRecipeArn.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        image_recipe_arn(Text, optional):  The Amazon Resource Name (ARN) of the image recipe that defines how images are configured,
            tested, and assessed. Defaults to None.
        container_recipe_arn(Text, optional): The Amazon Resource Name (ARN) of the container recipe that defines how images are configured
            and tested. Defaults to None.
        distribution_configuration_arn(Text, optional):  The Amazon Resource Name (ARN) of the distribution configuration that defines and configures
            the outputs of your pipeline. Defaults to None.
        infrastructure_configuration_arn(Text):  The Amazon Resource Name (ARN) of the infrastructure configuration that defines the environment
            in which your image will be built and tested.
        image_tests_configuration(Dict, optional):  The image tests configuration of the image. Defaults to None.
        enhanced_image_metadata_enabled(bool, optional):  Collects additional information about the image being created, including the operating system
            (OS) version and package list. This information is used to enhance the overall experience of
            using EC2 Image Builder. Enabled by default. Defaults to None.
        tags(Dict, optional):  The tags of the image. 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.present:
                - name: value
                - infrastructure_configuration_arn: value
                - client_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.imagebuilder.image.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(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.imagebuilder.create_image(
                ctx,
                
                
                **{"imageRecipeArn": image_recipe_arn, "containerRecipeArn": container_recipe_arn, "distributionConfigurationArn": distribution_configuration_arn, "infrastructureConfigurationArn": infrastructure_configuration_arn, "imageTestsConfiguration": image_tests_configuration, "enhancedImageMetadataEnabled": enhanced_image_metadata_enabled, "tags": tags, "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(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

