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

hub.exec.boto3.client.personalize.create_dataset
hub.exec.boto3.client.personalize.delete_dataset
hub.exec.boto3.client.personalize.describe_dataset
hub.exec.boto3.client.personalize.list_datasets
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, schema_arn: Text, dataset_group_arn: Text, dataset_type: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an empty dataset and adds it to the specified dataset group. Use CreateDatasetImportJob to import your
    training data to a dataset. There are three types of datasets:   Interactions   Items   Users   Each dataset
    type has an associated schema with required field types. Only the Interactions dataset is required in order to
    train a model (also referred to as creating a solution). A dataset 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 dataset, call DescribeDataset.  Related APIs     CreateDatasetGroup     ListDatasets
    DescribeDataset     DeleteDataset

    Args:
        name(Text): The name for the dataset.
        schema_arn(Text): The ARN of the schema to associate with the dataset. The schema defines the dataset fields.
        dataset_group_arn(Text): The Amazon Resource Name (ARN) of the dataset group to add the dataset to.
        dataset_type(Text): The type of dataset. One of the following (case insensitive) values:   Interactions   Items
            Users.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.personalize.create_dataset(
                ctx,
                
                
                **{"Name": name, "schemaArn": schema_arn, "datasetGroupArn": dataset_group_arn, "datasetType": dataset_type}
            )
            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_dataset(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, dataset_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a dataset. You can't delete a dataset if an associated DatasetImportJob or SolutionVersion is in the
    CREATE PENDING or IN PROGRESS state. For more information on datasets, see CreateDataset.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

