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

hub.exec.boto3.client.sagemaker.create_artifact
hub.exec.boto3.client.sagemaker.delete_artifact
hub.exec.boto3.client.sagemaker.describe_artifact
hub.exec.boto3.client.sagemaker.list_artifacts
hub.exec.boto3.client.sagemaker.update_artifact
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, source: Dict, artifact_type: Text, artifact_name: Text = None, properties: Dict = None, metadata_properties: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an artifact. An artifact is a lineage tracking entity that represents a URI addressable object or data.
    Some examples are the S3 URI of a dataset and the ECR registry path of an image. For more information, see
    Amazon SageMaker ML Lineage Tracking.   CreateArtifact can only be invoked from within an SageMaker managed
    environment. This includes SageMaker training jobs, processing jobs, transform jobs, and SageMaker notebooks. A
    call to CreateArtifact from outside one of these environments results in an error.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        artifact_name(Text, optional): The name of the artifact. Must be unique to your account in an Amazon Web Services Region. Defaults to None.
        source(Dict): The ID, ID type, and URI of the source.
        artifact_type(Text): The artifact type.
        properties(Dict, optional): A list of properties to add to the artifact. Defaults to None.
        metadata_properties(Dict, optional): Metadata properties of the tracking entity, trial, or trial component. Defaults to None.
        tags(List, optional): A list of tags to apply to the artifact. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_artifact(
                ctx,
                
                
                **{"ArtifactName": artifact_name, "Source": source, "ArtifactType": artifact_type, "Properties": properties, "MetadataProperties": metadata_properties, "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.sagemaker.describe_artifact(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, artifact_arn: Text = None, source: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an artifact. Either ArtifactArn or Source must be specified.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        artifact_arn(Text, optional): The Amazon Resource Name (ARN) of the artifact to delete. Defaults to None.
        source(Dict, optional): The URI of the source. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

