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

from api_validations.validations_request import (
    InsertBuildDecisionBookItems,
    UpdateBuildDecisionBookItems,
    ListDecisionBook,
    PatchRecord,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


build_decision_book_items_route = APIRouter(
    prefix="/build/decision_book/items", tags=["Decision Book Items"]
)
build_decision_book_items_route.include_router(
    build_decision_book_items_route, include_in_schema=True
)


@build_decision_book_items_route.post(
    path="/list", summary="List Active/Delete/Confirm Build Decision Book Items"
)
def build_decision_book_items_list(request: Request, data: ListDecisionBook):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


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


@build_decision_book_items_route.post(
    path="/update/{book_uu_id}",
    summary="Update Build Decision Book Items with given auth levels",
)
def build_decision_book_items_update(
    request: Request, book_uu_id: str, data: UpdateBuildDecisionBookItems
):
    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_decision_book_items_route.patch(
    path="/patch/{book_uu_id}", summary="Update Active/Delete/Confirm"
)
def build_decision_book_items_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
    )
