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

hub.exec.boto3.client.personalize.create_solution
hub.exec.boto3.client.personalize.delete_solution
hub.exec.boto3.client.personalize.describe_solution
hub.exec.boto3.client.personalize.list_solutions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, dataset_group_arn: Text, perform_hpo: bool = None, perform_auto_ml: bool = None, recipe_arn: Text = None, event_type: Text = None, solution_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates the configuration for training a model. A trained model is known as a solution. After the configuration
    is created, you train the model (create a solution) by calling the CreateSolutionVersion operation. Every time
    you call CreateSolutionVersion, a new version of the solution is created. After creating a solution version, you
    check its accuracy by calling GetSolutionMetrics. When you are satisfied with the version, you deploy it using
    CreateCampaign. The campaign provides recommendations to a client through the GetRecommendations API. To train a
    model, Amazon Personalize requires training data and a recipe. The training data comes from the dataset group
    that you provide in the request. A recipe specifies the training algorithm and a feature transformation. You can
    specify one of the predefined recipes provided by Amazon Personalize. Alternatively, you can specify
    performAutoML and Amazon Personalize will analyze your data and select the optimum USER_PERSONALIZATION recipe
    for you.  Amazon Personalize doesn't support configuring the hpoObjective for solution hyperparameter
    optimization at this time.   Status  A solution can be in one of the following states:   CREATE PENDING > CREATE
    IN_PROGRESS > ACTIVE -or- CREATE FAILED   DELETE PENDING > DELETE IN_PROGRESS   To get the status of the
    solution, call DescribeSolution. Wait until the status shows as ACTIVE before calling CreateSolutionVersion.
    Related APIs     ListSolutions     CreateSolutionVersion     DescribeSolution     DeleteSolution
    ListSolutionVersions     DescribeSolutionVersion

    Args:
        name(Text): The name for the solution.
        perform_hpo(bool, optional): Whether to perform hyperparameter optimization (HPO) on the specified or selected recipe. The
            default is false. When performing AutoML, this parameter is always true and you should not set
            it to false. Defaults to None.
        perform_auto_ml(bool, optional): Whether to perform automated machine learning (AutoML). The default is false. For this case, you
            must specify recipeArn. When set to true, Amazon Personalize analyzes your training data and
            selects the optimal USER_PERSONALIZATION recipe and hyperparameters. In this case, you must omit
            recipeArn. Amazon Personalize determines the optimal recipe by running tests with different
            values for the hyperparameters. AutoML lengthens the training process as compared to selecting a
            specific recipe. Defaults to None.
        recipe_arn(Text, optional): The ARN of the recipe to use for model training. Only specified when performAutoML is false. Defaults to None.
        dataset_group_arn(Text): The Amazon Resource Name (ARN) of the dataset group that provides the training data.
        event_type(Text, optional): When your have multiple event types (using an EVENT_TYPE schema field), this parameter specifies
            which event type (for example, 'click' or 'like') is used for training the model. If you do not
            provide an eventType, Amazon Personalize will use all interactions for training with equal
            weight regardless of type. Defaults to None.
        solution_config(Dict, optional): The configuration to use with the solution. When performAutoML is set to true, Amazon
            Personalize only evaluates the autoMLConfig section of the solution configuration.  Amazon
            Personalize doesn't support configuring the hpoObjective at this time. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.personalize.solution.present:
                - name: value
                - dataset_group_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.personalize.solution.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.personalize.describe_solution(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.personalize.create_solution(
                ctx,
                
                
                **{"Name": name, "performHPO": perform_hpo, "performAutoML": perform_auto_ml, "recipeArn": recipe_arn, "datasetGroupArn": dataset_group_arn, "eventType": event_type, "solutionConfig": solution_config}
            )
            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.personalize.describe_solution(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, solution_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes all versions of a solution and the Solution object itself. Before deleting a solution, you must delete
    all campaigns based on the solution. To determine what campaigns are using the solution, call ListCampaigns and
    supply the Amazon Resource Name (ARN) of the solution. You can't delete a solution if an associated
    SolutionVersion is in the CREATE PENDING or IN PROGRESS state. For more information on solutions, see
    CreateSolution.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

