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

hub.exec.boto3.client.iotanalytics.create_dataset
hub.exec.boto3.client.iotanalytics.delete_dataset
hub.exec.boto3.client.iotanalytics.describe_dataset
hub.exec.boto3.client.iotanalytics.list_datasets
hub.exec.boto3.client.iotanalytics.update_dataset
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, dataset_name: Text, actions: List, triggers: List = None, content_delivery_rules: List = None, retention_period: Dict = None, versioning_configuration: Dict = None, tags: List = None, late_data_rules: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Used to create a dataset. A dataset stores data retrieved from a data store by applying a queryAction (a SQL
    query) or a containerAction (executing a containerized application). This operation creates the skeleton of a
    dataset. The dataset can be populated manually by calling CreateDatasetContent or automatically according to a
    trigger you specify.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        dataset_name(Text): The name of the dataset.
        actions(List): A list of actions that create the dataset contents.
        triggers(List, optional): A list of triggers. A trigger causes dataset contents to be populated at a specified time
            interval or when another dataset's contents are created. The list of triggers can be empty or
            contain up to five DataSetTrigger objects. Defaults to None.
        content_delivery_rules(List, optional): When dataset contents are created, they are delivered to destinations specified here. Defaults to None.
        retention_period(Dict, optional): Optional. How long, in days, versions of dataset contents are kept for the dataset. If not
            specified or set to null, versions of dataset contents are retained for at most 90 days. The
            number of versions of dataset contents retained is determined by the versioningConfiguration
            parameter. For more information, see  Keeping Multiple Versions of IoT Analytics datasets in the
            IoT Analytics User Guide. Defaults to None.
        versioning_configuration(Dict, optional): Optional. How many versions of dataset contents are kept. If not specified or set to null, only
            the latest version plus the latest succeeded version (if they are different) are kept for the
            time period specified by the retentionPeriod parameter. For more information, see Keeping
            Multiple Versions of IoT Analytics datasets in the IoT Analytics User Guide. Defaults to None.
        tags(List, optional): Metadata which can be used to manage the dataset. Defaults to None.
        late_data_rules(List, optional): A list of data rules that send notifications to CloudWatch, when data arrives late. To specify
            lateDataRules, the dataset must use a DeltaTimer filter. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotanalytics.create_dataset(
                ctx,
                
                
                **{"datasetName": dataset_name, "actions": actions, "triggers": triggers, "contentDeliveryRules": content_delivery_rules, "retentionPeriod": retention_period, "versioningConfiguration": versioning_configuration, "tags": tags, "lateDataRules": late_data_rules}
            )
            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.iotanalytics.describe_dataset(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, dataset_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified dataset. You do not have to delete the content of the dataset before you perform this
    operation.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

