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

hub.exec.boto3.client.sagemaker.create_context
hub.exec.boto3.client.sagemaker.delete_context
hub.exec.boto3.client.sagemaker.describe_context
hub.exec.boto3.client.sagemaker.list_contexts
hub.exec.boto3.client.sagemaker.update_context
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, context_name: Text, source: Dict, context_type: Text, description: Text = None, properties: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a context. A context is a lineage tracking entity that represents a logical grouping of other tracking
    or experiment entities. Some examples are an endpoint and a model package. For more information, see Amazon
    SageMaker ML Lineage Tracking.   CreateContext 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
    CreateContext from outside one of these environments results in an error.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        context_name(Text): The name of the context. Must be unique to your account in an Amazon Web Services Region.
        source(Dict): The source type, ID, and URI.
        context_type(Text): The context type.
        description(Text, optional): The description of the context. Defaults to None.
        properties(Dict, optional): A list of properties to add to the context. Defaults to None.
        tags(List, optional): A list of tags to apply to the context. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_context(
                ctx,
                
                
                **{"ContextName": context_name, "Source": source, "ContextType": context_type, "Description": description, "Properties": 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_context(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        context_name(Text): The name of the context to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

