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

hub.exec.boto3.client.lakeformation.create_lf_tag
hub.exec.boto3.client.lakeformation.delete_lf_tag
hub.exec.boto3.client.lakeformation.get_lf_tag
hub.exec.boto3.client.lakeformation.list_lf_tags
hub.exec.boto3.client.lakeformation.update_lf_tag
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, tag_key: Text, tag_values: List, catalog_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a tag with the specified name and values.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        catalog_id(Text, optional): The identifier for the Data Catalog. By default, the account ID. The Data Catalog is the
            persistent metadata store. It contains database definitions, table definitions, and other
            control information to manage your AWS Lake Formation environment. Defaults to None.
        tag_key(Text): The key-name for the tag.
        tag_values(List): A list of possible values an attribute can take.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.lakeformation.lf_tag.present:
                - name: value
                - tag_key: value
                - tag_values: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lakeformation.lf_tag.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.lakeformation.get_lf_tag(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lakeformation.create_lf_tag(
                ctx,
                
                
                **{"CatalogId": catalog_id, "TagKey": tag_key, "TagValues": tag_values}
            )
            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.lakeformation.get_lf_tag(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, tag_key: Text, catalog_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified tag key name. If the attribute key does not exist or the tag does not exist, then the
    operation will not do anything. If the attribute key exists, then the operation checks if any resources are
    tagged with this attribute key, if yes, the API throws a 400 Exception with the message "Delete not allowed" as
    the tag key is still attached with resources. You can consider untagging resources with this tag key.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        catalog_id(Text, optional): The identifier for the Data Catalog. By default, the account ID. The Data Catalog is the
            persistent metadata store. It contains database definitions, table definitions, and other
            control information to manage your AWS Lake Formation environment. Defaults to None.
        tag_key(Text): The key-name for the tag to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

