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

hub.exec.boto3.client.glue.create_user_defined_function
hub.exec.boto3.client.glue.delete_user_defined_function
hub.exec.boto3.client.glue.get_user_defined_functions
hub.exec.boto3.client.glue.update_user_defined_function
"""



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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        catalog_id(Text, optional): The ID of the Data Catalog in which to create the function. 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 to create the function.
        function_input(Dict): A FunctionInput object that defines the function to create in the Data Catalog.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, database_name: Text, function_name: Text, catalog_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing function definition from the Data Catalog.

    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 function to be deleted is located. If none is supplied, the
            Amazon Web Services account ID is used by default. Defaults to None.
        database_name(Text): The name of the catalog database where the function is located.
        function_name(Text): The name of the function definition to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

