from fastapi.routing import APIRouter
from fastapi.requests import Request

from api_services.redis.auth_actions.token import parse_token_object_to_dict
from api_validations.validations_request import (
    RegisterEvents2Employee,
    RegisterEvents2Occupant,
    PatchRecord,
)


bind_events_route = APIRouter(prefix="/bind/events", tags=["Binds"])
bind_events_route.include_router(bind_events_route, include_in_schema=True)


@bind_events_route.post(path="/occupant", summary="Register Event to Occupant")
def bind_events_occupant(request: Request, data: RegisterEvents2Occupant):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@bind_events_route.post(path="/employee", summary="Register Event to Employee")
def bind_events_employee(request: Request, data: RegisterEvents2Employee):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@bind_events_route.patch(
    path="/patch/{event_uu_id}", summary="Patch Bind Events with given auth levels"
)
def bind_events_patch(request: Request, event_uu_id: str, data: PatchRecord):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, event_uu_id=event_uu_id, token_dict=token_dict
    )
