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

hub.exec.boto3.client.athena.create_work_group
hub.exec.boto3.client.athena.delete_work_group
hub.exec.boto3.client.athena.get_work_group
hub.exec.boto3.client.athena.list_work_groups
hub.exec.boto3.client.athena.update_work_group
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, configuration: Dict = None, description: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a workgroup with the specified name.

    Args:
        name(Text): The workgroup name.
        configuration(Dict, optional): The configuration for the workgroup, which includes the location in Amazon S3 where query
            results are stored, the encryption configuration, if any, used for encrypting query results,
            whether the Amazon CloudWatch Metrics are enabled for the workgroup, the limit for the amount of
            bytes scanned (cutoff) per query, if it is specified, and whether workgroup's settings
            (specified with EnforceWorkGroupConfiguration) in the WorkGroupConfiguration override client-
            side settings. See WorkGroupConfiguration$EnforceWorkGroupConfiguration. Defaults to None.
        description(Text, optional): The workgroup description. Defaults to None.
        tags(List, optional): A list of comma separated tags to add to the workgroup that is created. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.athena.create_work_group(
                ctx,
                
                
                **{"Name": name, "Configuration": configuration, "Description": description, "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.athena.get_work_group(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, work_group: Text, recursive_delete_option: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the workgroup with the specified name. The primary workgroup cannot be deleted.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        work_group(Text): The unique name of the workgroup to delete.
        recursive_delete_option(bool, optional): The option to delete the workgroup and its contents even if the workgroup contains any named
            queries or query executions. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

