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

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



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, input_: Dict, format_: Text = None, format_options: Dict = None, path_options: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new DataBrew dataset.

    Args:
        name(Text): The name of the dataset to be created. Valid characters are alphanumeric (A-Z, a-z, 0-9), hyphen
            (-), period (.), and space.
        format_(Text, optional): The file format of a dataset that is created from an Amazon S3 file or folder. Defaults to None.
        format_options(Dict, optional): Represents a set of options that define the structure of either comma-separated value (CSV),
            Excel, or JSON input. Defaults to None.
        input_(Dict): Represents information on how DataBrew can find data, in either the Glue Data Catalog or Amazon
            S3.
        path_options(Dict, optional): A set of options that defines how DataBrew interprets an Amazon S3 path of the dataset. Defaults to None.
        tags(Dict, optional): Metadata tags to apply to this dataset. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.databrew.create_dataset(
                ctx,
                
                
                **{"Name": name, "Format": format_, "FormatOptions": format_options, "Input": input_, "PathOptions": path_options, "Tags": tags}
            )
            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.databrew.describe_dataset(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a dataset from DataBrew.

    Args:
        name(Text): The name of the dataset to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

