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

from ApiServices.api_handlers.auth_actions.token import parse_token_object_to_dict
from api_validations.validations_request import (
    RegisterModules2Occupant,
    RegisterModules2Employee,
    PatchRecord,
)


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


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


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


@bind_modules_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
    )
