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

from api_validations.validations_request import (
    InsertDecisionBook,
    UpdateDecisionBook,
    PatchRecord,
    ListOptions,
)
from api_services.redis.auth_actions.token import parse_token_object_to_dict


build_project_decision_book_person_route = APIRouter(
    prefix="/build/decision_book/person", tags=["Decision Book Person"]
)
build_project_decision_book_person_route.include_router(
    build_project_decision_book_person_route, include_in_schema=True
)


@build_project_decision_book_person_route.post(
    path="/list", summary="List Active/Delete/Confirm Build Decision Book"
)
def project_decision_book_person_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)


@build_project_decision_book_person_route.post(
    path="/create", summary="Create Build Decision Book with given auth levels"
)
def project_decision_book_person_create(request: Request, data: InsertDecisionBook):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@build_project_decision_book_person_route.post(
    path="/update/{book_uu_id}",
    summary="Update Build Decision Book with given auth levels",
)
def project_decision_book_person_update(
    request: Request, book_uu_id: str, data: UpdateDecisionBook
):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, book_uu_id=book_uu_id, token_dict=token_dict
    )


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