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

hub.exec.boto3.client.personalize.create_dataset_group
hub.exec.boto3.client.personalize.delete_dataset_group
hub.exec.boto3.client.personalize.describe_dataset_group
hub.exec.boto3.client.personalize.list_dataset_groups
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, role_arn: Text = None, kms_key_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an empty dataset group. A dataset group contains related datasets that supply data for training a model.
    A dataset group can contain at most three datasets, one for each type of dataset:   Interactions   Items   Users
    To train a model (create a solution), a dataset group that contains an Interactions dataset is required. Call
    CreateDataset to add a dataset to the group. A dataset group can be in one of the following states:   CREATE
    PENDING > CREATE IN_PROGRESS > ACTIVE -or- CREATE FAILED   DELETE PENDING   To get the status of the dataset
    group, call DescribeDatasetGroup. If the status shows as CREATE FAILED, the response includes a failureReason
    key, which describes why the creation failed.  You must wait until the status of the dataset group is ACTIVE
    before adding a dataset to the group.  You can specify an Key Management Service (KMS) key to encrypt the
    datasets in the group. If you specify a KMS key, you must also include an Identity and Access Management (IAM)
    role that has permission to access the key.  APIs that require a dataset group ARN in the request
    CreateDataset     CreateEventTracker     CreateSolution     Related APIs     ListDatasetGroups
    DescribeDatasetGroup     DeleteDatasetGroup

    Args:
        name(Text): The name for the new dataset group.
        role_arn(Text, optional): The ARN of the Identity and Access Management (IAM) role that has permissions to access the Key
            Management Service (KMS) key. Supplying an IAM role is only valid when also specifying a KMS
            key. Defaults to None.
        kms_key_arn(Text, optional): The Amazon Resource Name (ARN) of a Key Management Service (KMS) key used to encrypt the
            datasets. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.personalize.create_dataset_group(
                ctx,
                
                
                **{"Name": name, "roleArn": role_arn, "kmsKeyArn": kms_key_arn}
            )
            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_group(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, dataset_group_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a dataset group. Before you delete a dataset group, you must delete the following:   All associated
    event trackers.   All associated solutions.   All datasets in the dataset group.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

