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

hub.exec.boto3.client.sagemaker.create_image_version
hub.exec.boto3.client.sagemaker.delete_image_version
hub.exec.boto3.client.sagemaker.describe_image_version
hub.exec.boto3.client.sagemaker.list_image_versions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, base_image: Text, image_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a version of the SageMaker image specified by ImageName. The version represents the Amazon Container
    Registry (ECR) container image specified by BaseImage.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        base_image(Text): The registry path of the container image to use as the starting point for this version. The path
            is an Amazon Container Registry (ECR) URI in the following format:  <acct-
            id>.dkr.ecr.<region>.amazonaws.com/<repo-name[:tag] or [@digest]>.
        image_name(Text): The ImageName of the Image to create a version of.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.sagemaker.image_version.present:
                - name: value
                - base_image: value
                - image_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sagemaker.image_version.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.sagemaker.describe_image_version(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_image_version(
                ctx,
                
                ClientToken=name,
                **{"BaseImage": base_image, "ImageName": image_name}
            )
            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.sagemaker.describe_image_version(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, image_name: Text, version: int)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a version of a SageMaker image. The container image the version represents isn't deleted.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        image_name(Text): The name of the image.
        version(int): The version to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

