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

hub.exec.boto3.client.glue.create_workflow
hub.exec.boto3.client.glue.delete_workflow
hub.exec.boto3.client.glue.get_workflow
hub.exec.boto3.client.glue.list_workflows
hub.exec.boto3.client.glue.update_workflow
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, description: Text = None, default_run_properties: Dict = None, tags: Dict = None, max_concurrent_runs: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new workflow.

    Args:
        name(Text): The name to be assigned to the workflow. It should be unique within your account.
        description(Text, optional): A description of the workflow. Defaults to None.
        default_run_properties(Dict, optional): A collection of properties to be used as part of each execution of the workflow. Defaults to None.
        tags(Dict, optional): The tags to be used with this workflow. Defaults to None.
        max_concurrent_runs(int, optional): You can use this parameter to prevent unwanted multiple updates to data, to control costs, or in
            some cases, to prevent exceeding the maximum number of concurrent runs of any of the component
            jobs. If you leave this parameter blank, there is no limit to the number of concurrent workflow
            runs. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.glue.create_workflow(
                ctx,
                
                
                **{"Name": name, "Description": description, "DefaultRunProperties": default_run_properties, "Tags": tags, "MaxConcurrentRuns": max_concurrent_runs}
            )
            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_workflow(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a workflow.

    Args:
        name(Text): Name of the workflow to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

