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

hub.exec.boto3.client.glue.create_trigger
hub.exec.boto3.client.glue.delete_trigger
hub.exec.boto3.client.glue.get_triggers
hub.exec.boto3.client.glue.list_triggers
hub.exec.boto3.client.glue.start_trigger
hub.exec.boto3.client.glue.stop_trigger
hub.exec.boto3.client.glue.update_trigger
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, type_: Text, actions: List, workflow_name: Text = None, schedule: Text = None, predicate: Dict = None, description: Text = None, start_on_creation: bool = None, tags: Dict = None, event_batching_condition: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new trigger.

    Args:
        name(Text): The name of the trigger.
        workflow_name(Text, optional): The name of the workflow associated with the trigger. Defaults to None.
        type_(Text): The type of the new trigger.
        schedule(Text, optional): A cron expression used to specify the schedule (see Time-Based Schedules for Jobs and Crawlers.
            For example, to run something every day at 12:15 UTC, you would specify: cron(15 12 * * ? *).
            This field is required when the trigger type is SCHEDULED. Defaults to None.
        predicate(Dict, optional): A predicate to specify when the new trigger should fire. This field is required when the trigger
            type is CONDITIONAL. Defaults to None.
        actions(List): The actions initiated by this trigger when it fires.
        description(Text, optional): A description of the new trigger. Defaults to None.
        start_on_creation(bool, optional): Set to true to start SCHEDULED and CONDITIONAL triggers when created. True is not supported for
            ON_DEMAND triggers. Defaults to None.
        tags(Dict, optional): The tags to use with this trigger. You may use tags to limit access to the trigger. For more
            information about tags in Glue, see Amazon Web Services Tags in Glue in the developer guide. Defaults to None.
        event_batching_condition(Dict, optional): Batch condition that must be met (specified number of events received or batch time window
            expired) before EventBridge event trigger fires. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.glue.create_trigger(
                ctx,
                
                
                **{"Name": name, "WorkflowName": workflow_name, "Type": type_, "Schedule": schedule, "Predicate": predicate, "Actions": actions, "Description": description, "StartOnCreation": start_on_creation, "Tags": tags, "EventBatchingCondition": event_batching_condition}
            )
            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_triggers(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 specified trigger. If the trigger is not found, no exception is thrown.

    Args:
        name(Text): The name of the trigger to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

