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

hub.exec.boto3.client.athena.create_named_query
hub.exec.boto3.client.athena.delete_named_query
hub.exec.boto3.client.athena.get_named_query
hub.exec.boto3.client.athena.list_named_queries
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, database: Text, query_string: Text, description: Text = None, client_request_token: Text = None, work_group: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a named query in the specified workgroup. Requires that you have access to the workgroup. For code
    samples using the Amazon Web Services SDK for Java, see Examples and Code Samples in the Amazon Athena User
    Guide.

    Args:
        name(Text): The query name.
        description(Text, optional): The query description. Defaults to None.
        database(Text): The database to which the query belongs.
        query_string(Text): The contents of the query with all query statements.
        client_request_token(Text, optional): A unique case-sensitive string used to ensure the request to create the query is idempotent
            (executes only once). If another CreateNamedQuery request is received, the same response is
            returned and another query is not created. If a parameter has changed, for example, the
            QueryString, an error is returned.  This token is listed as not required because Amazon Web
            Services SDKs (for example the Amazon Web Services SDK for Java) auto-generate the token for
            users. If you are not using the Amazon Web Services SDK or the Amazon Web Services CLI, you must
            provide this token or the action will fail. Defaults to None.
        work_group(Text, optional): The name of the workgroup in which the named query is being created. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.athena.create_named_query(
                ctx,
                
                
                **{"Name": name, "Description": description, "Database": database, "QueryString": query_string, "ClientRequestToken": client_request_token, "WorkGroup": work_group}
            )
            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_named_query(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, named_query_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the named query if you have access to the workgroup in which the query was saved. For code samples using
    the Amazon Web Services SDK for Java, see Examples and Code Samples in the Amazon Athena User Guide.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

