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

from api_validations.validations_request import (
    InsertBuildDecisionBookProjects,
    UpdateBuildDecisionBookProjects,
    PatchRecord,
    ListOptions,
)
from api_services.redis.auth_actions.token import parse_token_object_to_dict


build_project_decision_book_route = APIRouter(
    prefix="/build/project/decision_book", tags=["Project Decision Book"]
)
build_project_decision_book_route.include_router(
    build_project_decision_book_route, include_in_schema=True
)


@build_project_decision_book_route.post(
    path="/list", summary="List Active/Delete/Confirm Project Build Decision Book"
)
def project_decision_book_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_route.post(
    path="/create", summary="Create Build Project Decision Book with given auth levels"
)
def project_decision_book_create(
    request: Request, data: InsertBuildDecisionBookProjects
):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@build_project_decision_book_route.post(
    path="/update/{book_uu_id}",
    summary="Update Project Build Decision Book with given auth levels",
)
def project_decision_book_update(
    request: Request, book_uu_id: str, data: UpdateBuildDecisionBookProjects
):
    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_route.patch(
    path="/patch/{book_uu_id}", summary="Update Active/Delete/Confirm"
)
def project_decision_book_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
    )
