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

hub.exec.boto3.client.lookoutvision.create_dataset
hub.exec.boto3.client.lookoutvision.delete_dataset
hub.exec.boto3.client.lookoutvision.describe_dataset
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, project_name: Text, dataset_type: Text, dataset_source: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new dataset in an Amazon Lookout for Vision project. CreateDataset can create a training or a test
    dataset from a valid dataset source (DatasetSource). If you want a single dataset project, specify train for the
    value of DatasetType. To have a project with separate training and test datasets, call CreateDataset twice. On
    the first call, specify train for the value of DatasetType. On the second call, specify test for the value of
    DatasetType.  This operation requires permissions to perform the lookoutvision:CreateDataset operation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_name(Text): The name of the project in which you want to create a dataset.
        dataset_type(Text): The type of the dataset. Specify train for a training dataset. Specify test for a test dataset.
        dataset_source(Dict, optional): The location of the manifest file that Amazon Lookout for Vision uses to create the dataset. If
            you don't specify DatasetSource, an empty dataset is created and the operation synchronously
            returns. Later, you can add JSON Lines by calling UpdateDatasetEntries.  If you specify a value
            for DataSource, the manifest at the S3 location is validated and used to create the dataset. The
            call to CreateDataset is asynchronous and might take a while to complete. To find out the
            current status, Check the value of Status returned in a call to DescribeDataset. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lookoutvision.create_dataset(
                ctx,
                
                ClientToken=name,
                **{"ProjectName": project_name, "DatasetType": dataset_type, "DatasetSource": dataset_source}
            )
            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.lookoutvision.describe_dataset(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, project_name: Text, dataset_type: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing Amazon Lookout for Vision dataset.  If your the project has a single dataset, you must
    create a new dataset before you can create a model. If you project has a training dataset and a test dataset
    consider the following.    If you delete the test dataset, your project reverts to a single dataset project. If
    you then train the model, Amazon Lookout for Vision internally splits the remaining dataset into a training and
    test dataset.   If you delete the training dataset, you must create a training dataset before you can create a
    model.   This operation requires permissions to perform the lookoutvision:DeleteDataset operation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        project_name(Text): The name of the project that contains the dataset that you want to delete.
        dataset_type(Text): The type of the dataset to delete. Specify train to delete the training dataset. Specify test to
            delete the test dataset. To delete the dataset in a single dataset project, specify train.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

