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

hub.exec.boto3.client.iotanalytics.create_datastore
hub.exec.boto3.client.iotanalytics.delete_datastore
hub.exec.boto3.client.iotanalytics.describe_datastore
hub.exec.boto3.client.iotanalytics.list_datastores
hub.exec.boto3.client.iotanalytics.update_datastore
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, datastore_name: Text, datastore_storage: Dict = None, retention_period: Dict = None, tags: List = None, file_format_configuration: Dict = None, datastore_partitions: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a data store, which is a repository for messages.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        datastore_name(Text): The name of the data store.
        datastore_storage(Dict, optional): Where data in a data store is stored.. You can choose serviceManagedS3 storage,
            customerManagedS3 storage, or iotSiteWiseMultiLayerStorage storage. The default is
            serviceManagedS3. You can't change the choice of Amazon S3 storage after your data store is
            created. Defaults to None.
        retention_period(Dict, optional): How long, in days, message data is kept for the data store. When customerManagedS3 storage is
            selected, this parameter is ignored. Defaults to None.
        tags(List, optional): Metadata which can be used to manage the data store. Defaults to None.
        file_format_configuration(Dict, optional): Contains the configuration information of file formats. IoT Analytics data stores support JSON
            and Parquet. The default file format is JSON. You can specify only one format. You can't change
            the file format after you create the data store. Defaults to None.
        datastore_partitions(Dict, optional):  Contains information about the partition dimensions in a data store. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iotanalytics.create_datastore(
                ctx,
                
                
                **{"datastoreName": datastore_name, "datastoreStorage": datastore_storage, "retentionPeriod": retention_period, "tags": tags, "fileFormatConfiguration": file_format_configuration, "datastorePartitions": datastore_partitions}
            )
            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_datastore(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, datastore_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified data store.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

