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

hub.exec.boto3.client.forecast.create_predictor
hub.exec.boto3.client.forecast.delete_predictor
hub.exec.boto3.client.forecast.describe_predictor
hub.exec.boto3.client.forecast.list_predictors
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, predictor_name: Text, forecast_horizon: int, input_data_config: Dict, featurization_config: Dict, algorithm_arn: Text = None, forecast_types: List = None, perform_auto_ml: bool = None, auto_ml_override_strategy: Text = None, perform_hpo: bool = None, training_parameters: Dict = None, evaluation_parameters: Dict = None, hpo_config: Dict = None, encryption_config: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon Forecast predictor. In the request, provide a dataset group and either specify an algorithm or
    let Amazon Forecast choose an algorithm for you using AutoML. If you specify an algorithm, you also can override
    algorithm-specific hyperparameters. Amazon Forecast uses the algorithm to train a predictor using the latest
    version of the datasets in the specified dataset group. You can then generate a forecast using the
    CreateForecast operation.  To see the evaluation metrics, use the GetAccuracyMetrics operation.  You can specify
    a featurization configuration to fill and aggregate the data fields in the TARGET_TIME_SERIES dataset to improve
    model training. For more information, see FeaturizationConfig. For RELATED_TIME_SERIES datasets, CreatePredictor
    verifies that the DataFrequency specified when the dataset was created matches the ForecastFrequency.
    TARGET_TIME_SERIES datasets don't have this restriction. Amazon Forecast also verifies the delimiter and
    timestamp format. For more information, see howitworks-datasets-groups. By default, predictors are trained and
    evaluated at the 0.1 (P10), 0.5 (P50), and 0.9 (P90) quantiles. You can choose custom forecast types to train
    and evaluate your predictor by setting the ForecastTypes.   AutoML  If you want Amazon Forecast to evaluate each
    algorithm and choose the one that minimizes the objective function, set PerformAutoML to true. The objective
    function is defined as the mean of the weighted losses over the forecast types. By default, these are the p10,
    p50, and p90 quantile losses. For more information, see EvaluationResult. When AutoML is enabled, the following
    properties are disallowed:    AlgorithmArn     HPOConfig     PerformHPO     TrainingParameters    To get a list
    of all of your predictors, use the ListPredictors operation.  Before you can use the predictor to create a
    forecast, the Status of the predictor must be ACTIVE, signifying that training has completed. To get the status,
    use the DescribePredictor operation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        predictor_name(Text): A name for the predictor.
        algorithm_arn(Text, optional): The Amazon Resource Name (ARN) of the algorithm to use for model training. Required if
            PerformAutoML is not set to true.  Supported algorithms:     arn:aws:forecast:::algorithm/ARIMA
            arn:aws:forecast:::algorithm/CNN-QR     arn:aws:forecast:::algorithm/Deep_AR_Plus
            arn:aws:forecast:::algorithm/ETS     arn:aws:forecast:::algorithm/NPTS
            arn:aws:forecast:::algorithm/Prophet. Defaults to None.
        forecast_horizon(int): Specifies the number of time-steps that the model is trained to predict. The forecast horizon is
            also called the prediction length. For example, if you configure a dataset for daily data
            collection (using the DataFrequency parameter of the CreateDataset operation) and set the
            forecast horizon to 10, the model returns predictions for 10 days. The maximum forecast horizon
            is the lesser of 500 time-steps or 1/3 of the TARGET_TIME_SERIES dataset length.
        forecast_types(List, optional): Specifies the forecast types used to train a predictor. You can specify up to five forecast
            types. Forecast types can be quantiles from 0.01 to 0.99, by increments of 0.01 or higher. You
            can also specify the mean forecast with mean.  The default value is ["0.10", "0.50", "0.9"]. Defaults to None.
        perform_auto_ml(bool, optional): Whether to perform AutoML. When Amazon Forecast performs AutoML, it evaluates the algorithms it
            provides and chooses the best algorithm and configuration for your training dataset. The default
            value is false. In this case, you are required to specify an algorithm. Set PerformAutoML to
            true to have Amazon Forecast perform AutoML. This is a good option if you aren't sure which
            algorithm is suitable for your training data. In this case, PerformHPO must be false. Defaults to None.
        auto_ml_override_strategy(Text, optional): Used to overide the default AutoML strategy, which is to optimize predictor accuracy. To apply
            an AutoML strategy that minimizes training time, use LatencyOptimized. This parameter is only
            valid for predictors trained using AutoML. Defaults to None.
        perform_hpo(bool, optional): Whether to perform hyperparameter optimization (HPO). HPO finds optimal hyperparameter values
            for your training data. The process of performing HPO is known as running a hyperparameter
            tuning job. The default value is false. In this case, Amazon Forecast uses default
            hyperparameter values from the chosen algorithm. To override the default values, set PerformHPO
            to true and, optionally, supply the HyperParameterTuningJobConfig object. The tuning job
            specifies a metric to optimize, which hyperparameters participate in tuning, and the valid range
            for each tunable hyperparameter. In this case, you are required to specify an algorithm and
            PerformAutoML must be false. The following algorithms support HPO:   DeepAR+   CNN-QR. Defaults to None.
        training_parameters(Dict, optional): The hyperparameters to override for model training. The hyperparameters that you can override
            are listed in the individual algorithms. For the list of supported algorithms, see aws-forecast-
            choosing-recipes. Defaults to None.
        evaluation_parameters(Dict, optional): Used to override the default evaluation parameters of the specified algorithm. Amazon Forecast
            evaluates a predictor by splitting a dataset into training data and testing data. The evaluation
            parameters define how to perform the split and the number of iterations. Defaults to None.
        hpo_config(Dict, optional): Provides hyperparameter override values for the algorithm. If you don't provide this parameter,
            Amazon Forecast uses default values. The individual algorithms specify which hyperparameters
            support hyperparameter optimization (HPO). For more information, see aws-forecast-choosing-
            recipes. If you included the HPOConfig object, you must set PerformHPO to true. Defaults to None.
        input_data_config(Dict): Describes the dataset group that contains the data to use to train the predictor.
        featurization_config(Dict): The featurization configuration.
        encryption_config(Dict, optional): An AWS Key Management Service (KMS) key and the AWS Identity and Access Management (IAM) role
            that Amazon Forecast can assume to access the key. Defaults to None.
        tags(List, optional): The optional metadata that you apply to the predictor to help you categorize and organize them.
            Each tag consists of a key and an optional value, both of which you define. The following basic
            restrictions apply to tags:   Maximum number of tags per resource - 50.   For each resource,
            each tag key must be unique, and each tag key can have only one value.   Maximum key length -
            128 Unicode characters in UTF-8.   Maximum value length - 256 Unicode characters in UTF-8.   If
            your tagging schema is used across multiple services and resources, remember that other services
            may have restrictions on allowed characters. Generally allowed characters are: letters, numbers,
            and spaces representable in UTF-8, and the following characters: + - = . _ : / @.   Tag keys and
            values are case sensitive.   Do not use aws:, AWS:, or any upper or lowercase combination of
            such as a prefix for keys as it is reserved for AWS use. You cannot edit or delete tag keys with
            this prefix. Values can have this prefix. If a tag value has aws as its prefix but the key does
            not, then Forecast considers it to be a user tag and will count against the limit of 50 tags.
            Tags with only the key prefix of aws do not count against your tags per resource limit. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.forecast.predictor.present:
                - name: value
                - predictor_name: value
                - forecast_horizon: value
                - input_data_config: value
                - featurization_config: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.forecast.predictor.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.forecast.describe_predictor(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.forecast.create_predictor(
                ctx,
                
                
                **{"PredictorName": predictor_name, "AlgorithmArn": algorithm_arn, "ForecastHorizon": forecast_horizon, "ForecastTypes": forecast_types, "PerformAutoML": perform_auto_ml, "AutoMLOverrideStrategy": auto_ml_override_strategy, "PerformHPO": perform_hpo, "TrainingParameters": training_parameters, "EvaluationParameters": evaluation_parameters, "HPOConfig": hpo_config, "InputDataConfig": input_data_config, "FeaturizationConfig": featurization_config, "EncryptionConfig": encryption_config, "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.forecast.describe_predictor(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, predictor_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a predictor created using the CreatePredictor operation. You can delete only predictor that have a
    status of ACTIVE or CREATE_FAILED. To get the status, use the DescribePredictor operation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        predictor_arn(Text): The Amazon Resource Name (ARN) of the predictor to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

