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

hub.exec.boto3.client.redshift.create_scheduled_action
hub.exec.boto3.client.redshift.delete_scheduled_action
hub.exec.boto3.client.redshift.describe_scheduled_actions
hub.exec.boto3.client.redshift.modify_scheduled_action
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, scheduled_action_name: Text, target_action: Dict, schedule: Text, iam_role: Text, scheduled_action_description: Text = None, start_time: Text = None, end_time: Text = None, enable: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a scheduled action. A scheduled action contains a schedule and an Amazon Redshift API action. For
    example, you can create a schedule of when to run the ResizeCluster API operation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        scheduled_action_name(Text): The name of the scheduled action. The name must be unique within an account. For more
            information about this parameter, see ScheduledAction.
        target_action(Dict): A JSON format string of the Amazon Redshift API operation with input parameters. For more
            information about this parameter, see ScheduledAction.
        schedule(Text): The schedule in at( ) or cron( ) format. For more information about this parameter, see
            ScheduledAction.
        iam_role(Text): The IAM role to assume to run the target action. For more information about this parameter, see
            ScheduledAction.
        scheduled_action_description(Text, optional): The description of the scheduled action. Defaults to None.
        start_time(Text, optional): The start time in UTC of the scheduled action. Before this time, the scheduled action does not
            trigger. For more information about this parameter, see ScheduledAction. Defaults to None.
        end_time(Text, optional): The end time in UTC of the scheduled action. After this time, the scheduled action does not
            trigger. For more information about this parameter, see ScheduledAction. Defaults to None.
        enable(bool, optional): If true, the schedule is enabled. If false, the scheduled action does not trigger. For more
            information about state of the scheduled action, see ScheduledAction. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.redshift.scheduled_action.present:
                - name: value
                - scheduled_action_name: value
                - target_action: value
                - schedule: value
                - iam_role: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.scheduled_action.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.redshift.describe_scheduled_actions(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.create_scheduled_action(
                ctx,
                
                
                **{"ScheduledActionName": scheduled_action_name, "TargetAction": target_action, "Schedule": schedule, "IamRole": iam_role, "ScheduledActionDescription": scheduled_action_description, "StartTime": start_time, "EndTime": end_time, "Enable": enable}
            )
            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.redshift.describe_scheduled_actions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        scheduled_action_name(Text): The name of the scheduled action to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

