# This file was generated by symflow CLI vSYM_TEMPLATE_VAR_SYMFLOW_VERSION on SYM_TEMPLATE_VAR_GENERATION_TIME UTC.
# Modify this file to create custom logic that grants/removes access to third-party or internal services to manage
# them via Sym.


def lambda_handler(event, context):
    # The full structure of the Payload sent is described in the Sym Docs:
    # https://docs.symops.com/docs/aws-lambda#payload
    print(event)

    event_type = event["event"]["type"]
    requester = event["run"]["actors"]["request"]["username"]

    # This Lambda is invoked for both escalate and de-escalate, so we must branch logic based on the event type.
    if event_type == "escalate":
        return grant_access(requester)
    elif event_type == "deescalate":
        return remove_access(requester)


def grant_access(requester):
    # ... TODO: Write your custom escalation logic here! ...

    # body.message will be sent to the requester via Slack using an after_escalate hook
    # in impls/aws_lambda_SYM_TEMPLATE_VAR_FLOW_RESOURCE_NAME_impl.py.
    return {
        "body": {
            "message": "Your Lambda escalation ran successfully! Check out `SYM_TEMPLATE_VAR_LAMBDA_SOURCE_DIRECTORY/handler.py` to see how this message was sent."
        },
        "errors": [],
    }


def remove_access(requester):
    # ... TODO: Write your custom de-escalation logic here! ...

    # body.message will be sent to the requester via Slack using an after_deescalate hook
    # in impls/aws_lambda_SYM_TEMPLATE_VAR_FLOW_RESOURCE_NAME_impl.py.
    return {
        "body": {
            "message": "Your Lambda de-escalation ran successfully! Check out `SYM_TEMPLATE_VAR_LAMBDA_SOURCE_DIRECTORY/handler.py` to see how this message was sent."
        },
        "errors": []
    }
