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

hub.exec.boto3.client.glue.create_partition
hub.exec.boto3.client.glue.delete_partition
hub.exec.boto3.client.glue.get_partitions
hub.exec.boto3.client.glue.update_partition
"""



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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        catalog_id(Text, optional): The Amazon Web Services account ID of the catalog in which the partition is to be created. Defaults to None.
        database_name(Text): The name of the metadata database in which the partition is to be created.
        table_name(Text): The name of the metadata table in which the partition is to be created.
        partition_input(Dict): A PartitionInput structure defining the partition to be created.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        catalog_id(Text, optional): The ID of the Data Catalog where the partition to be deleted resides. If none is provided, the
            Amazon Web Services account ID is used by default. Defaults to None.
        database_name(Text): The name of the catalog database in which the table in question resides.
        table_name(Text): The name of the table that contains the partition to be deleted.
        partition_values(List): The values that define the partition.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

