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

hub.exec.boto3.client.sagemaker.create_trial
hub.exec.boto3.client.sagemaker.delete_trial
hub.exec.boto3.client.sagemaker.describe_trial
hub.exec.boto3.client.sagemaker.list_trials
hub.exec.boto3.client.sagemaker.update_trial
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, trial_name: Text, experiment_name: Text, display_name: Text = None, metadata_properties: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an SageMaker trial. A trial is a set of steps called trial components that produce a machine learning
    model. A trial is part of a single SageMaker experiment. When you use SageMaker Studio or the SageMaker Python
    SDK, all experiments, trials, and trial components are automatically tracked, logged, and indexed. When you use
    the Amazon Web Services SDK for Python (Boto), you must use the logging APIs provided by the SDK. You can add
    tags to a trial and then use the Search API to search for the tags. To get a list of all your trials, call the
    ListTrials API. To view a trial's properties, call the DescribeTrial API. To create a trial component, call the
    CreateTrialComponent API.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        trial_name(Text): The name of the trial. The name must be unique in your Amazon Web Services account and is not
            case-sensitive.
        display_name(Text, optional): The name of the trial as displayed. The name doesn't need to be unique. If DisplayName isn't
            specified, TrialName is displayed. Defaults to None.
        experiment_name(Text): The name of the experiment to associate the trial with.
        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 associate with the trial. You can use Search API to search on the tags. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_trial(
                ctx,
                
                
                **{"TrialName": trial_name, "DisplayName": display_name, "ExperimentName": experiment_name, "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_trial(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, trial_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified trial. All trial components that make up the trial must be deleted first. Use the
    DescribeTrialComponent API to get the list of trial components.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

