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

hub.exec.boto3.client.sagemaker.create_algorithm
hub.exec.boto3.client.sagemaker.delete_algorithm
hub.exec.boto3.client.sagemaker.describe_algorithm
hub.exec.boto3.client.sagemaker.list_algorithms
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, algorithm_name: Text, training_specification: Dict, algorithm_description: Text = None, inference_specification: Dict = None, validation_specification: Dict = None, certify_for_marketplace: bool = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create a machine learning algorithm that you can use in Amazon SageMaker and list in the Amazon Web Services
    Marketplace.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        algorithm_name(Text): The name of the algorithm.
        algorithm_description(Text, optional): A description of the algorithm. Defaults to None.
        training_specification(Dict): Specifies details about training jobs run by this algorithm, including the following:   The
            Amazon ECR path of the container and the version digest of the algorithm.   The hyperparameters
            that the algorithm supports.   The instance types that the algorithm supports for training.
            Whether the algorithm supports distributed training.   The metrics that the algorithm emits to
            Amazon CloudWatch.   Which metrics that the algorithm emits can be used as the objective metric
            for hyperparameter tuning jobs.   The input channels that the algorithm supports for training
            data. For example, an algorithm might support train, validation, and test channels.
        inference_specification(Dict, optional): Specifies details about inference jobs that the algorithm runs, including the following:   The
            Amazon ECR paths of containers that contain the inference code and model artifacts.   The
            instance types that the algorithm supports for transform jobs and real-time endpoints used for
            inference.   The input and output content formats that the algorithm supports for inference. Defaults to None.
        validation_specification(Dict, optional): Specifies configurations for one or more training jobs and that Amazon SageMaker runs to test
            the algorithm's training code and, optionally, one or more batch transform jobs that Amazon
            SageMaker runs to test the algorithm's inference code. Defaults to None.
        certify_for_marketplace(bool, optional): Whether to certify the algorithm so that it can be listed in Amazon Web Services Marketplace. Defaults to None.
        tags(List, optional): An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources
            in different ways, for example, by purpose, owner, or environment. For more information, see
            Tagging Amazon Web Services Resources. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_algorithm(
                ctx,
                
                
                **{"AlgorithmName": algorithm_name, "AlgorithmDescription": algorithm_description, "TrainingSpecification": training_specification, "InferenceSpecification": inference_specification, "ValidationSpecification": validation_specification, "CertifyForMarketplace": certify_for_marketplace, "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_algorithm(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, algorithm_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes the specified algorithm from your account.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

