from sym.sdk.annotations import hook, reducer
from sym.sdk.integrations import slack
from sym.sdk.templates import get_step_output


# Reducers fill in the blanks that your workflow needs in order to run.
# For more information, please see https://docs.symops.com/docs/reducers
@reducer
def get_approvers(event):
    """Route Sym requests to a specified channel."""

    # Make sure that this channel has been created in your workspace!
    return slack.channel("#sym-requests", allow_self=True)


@hook
def after_escalate(event):
    # `get_step_output` retrieves the response from the Lambda function
    # that was invoked by the `escalate` step.
    output = get_step_output("escalate")

    # This output message is defined in `SYM_TEMPLATE_VAR_FLOW_RESOURCE_NAME_lambda_src/handler.py`
    slack.send_message(event.get_actor("request"), output["body"]["message"])


@hook
def after_deescalate(event):
    # `get_step_output` retrieves the response from the Lambda function
    # that was invoked by the `deescalate` step.
    output = get_step_output("deescalate")

    # This output message is defined in `SYM_TEMPLATE_VAR_FLOW_RESOURCE_NAME_lambda_src/handler.py`
    slack.send_message(event.get_actor("request"), output["body"]["message"])
