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

from api_validations.validations_request import (
    InsertPerson,
    UpdateUsers,
    PatchRecord,
    ListOptions,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


people_router = APIRouter(prefix="/people", tags=["People"])
people_router.include_router(people_router, include_in_schema=True)


@people_router.post(path="/list", summary="List Active/Delete/Confirm People")
def people_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)


@people_router.post(path="/create", summary="Create People with given auth levels")
def people_create(request: Request, data: InsertPerson):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@people_router.post(
    path="/update/{user_uu_id}", summary="Update People with given auth levels"
)
def people_update(request: Request, user_uu_id: str, data: UpdateUsers):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, user_uu_id=user_uu_id, token_dict=token_dict
    )


@people_router.patch(path="/patch/{user_uu_id}", summary="Update Active/Delete/Confirm")
def people_patch(request: Request, user_uu_id: str, data: PatchRecord):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, user_uu_id=user_uu_id, token_dict=token_dict
    )
