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

from api_validations.validations_request import (
    DepartmentsPydantic,
    PatchRecord,
    ListOptions,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


modules_route = APIRouter(prefix="/modules", tags=["Modules"])
modules_route.include_router(modules_route, include_in_schema=True)


@modules_route.post(path="/list", summary="List Active/Delete/Confirm Modules")
def modules_list(request: Request, list_options: ListOptions):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(list_options=list_options, token_dict=token_dict)


@modules_route.post(path="/create", summary="Create Modules with given auth levels")
def modules_create(request: Request, data: DepartmentsPydantic):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@modules_route.post(
    path="/update/{module_uu_id}", summary="Update Modules with given auth levels"
)
def modules_update(request: Request, module_uu_id: str, data: DepartmentsPydantic):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, module_uu_id=module_uu_id, token_dict=token_dict
    )


@modules_route.patch(
    path="/patch/{module_uu_id}", summary="Patch Modules with given auth levels"
)
def modules_patch(request: Request, module_uu_id: str, data: PatchRecord):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, module_uu_id=module_uu_id, token_dict=token_dict
    )
