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

hub.exec.boto3.client.glue.create_partition_index
hub.exec.boto3.client.glue.delete_partition_index
hub.exec.boto3.client.glue.get_partition_indexes
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, database_name: Text, table_name: Text, partition_index: Dict, catalog_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a specified partition index in an existing table.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        catalog_id(Text, optional): The catalog ID where the table resides. Defaults to None.
        database_name(Text): Specifies the name of a database in which you want to create a partition index.
        table_name(Text): Specifies the name of a table in which you want to create a partition index.
        partition_index(Dict): Specifies a PartitionIndex structure to create a partition index in an existing table.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.glue.partition_index.present:
                - name: value
                - database_name: value
                - table_name: value
                - partition_index: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.glue.partition_index.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.glue.get_partition_indexes(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.glue.create_partition_index(
                ctx,
                
                
                **{"CatalogId": catalog_id, "DatabaseName": database_name, "TableName": table_name, "PartitionIndex": partition_index}
            )
            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.glue.get_partition_indexes(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, database_name: Text, table_name: Text, index_name: Text, catalog_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a specified partition index from an existing table.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        catalog_id(Text, optional): The catalog ID where the table resides. Defaults to None.
        database_name(Text): Specifies the name of a database from which you want to delete a partition index.
        table_name(Text): Specifies the name of a table from which you want to delete a partition index.
        index_name(Text): The name of the partition index to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.glue.partition_index.absent:
                - name: value
                - database_name: value
                - table_name: value
                - index_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.glue.partition_index.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.glue.get_partition_indexes(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.glue.delete_partition_index(
                ctx,
                
                
                **{"CatalogId": catalog_id, "DatabaseName": database_name, "TableName": table_name, "IndexName": index_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.glue.get_partition_indexes(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

