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

from api_validations.validations_request import (
    InsertDecisionBook,
    UpdateDecisionBook,
    DecisionBookDecisionBookInvitations,
    PatchRecord,
    ListOptions,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


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


@build_decision_book_route.post(
    path="/list", summary="List Active/Delete/Confirm Build Decision Book"
)
def build_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_decision_book_route.post(
    path="/create", summary="Create Build Decision Book with given auth levels"
)
def build_decision_book_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_decision_book_route.post(
    path="/approval", summary="Approve Build Decision Book with given auth levels"
)
def build_decision_book_approval(request: Request, data):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@build_decision_book_route.post(
    path="/update/{book_uu_id}",
    summary="Update Build Decision Book with given auth levels",
)
def build_decision_book_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, token_dict=token_dict)


@build_decision_book_route.patch(
    path="/patch/{book_uu_id}", summary="Update Active/Delete/Confirm"
)
def build_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, token_dict=token_dict)


@build_decision_book_route.post(
    path="/invite/list", summary="List Build Decision Book Invitations"
)
def build_decision_book_invite(request: Request, data: ListOptions):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(list_options=data, token_dict=token_dict)


@build_decision_book_route.post(
    path="/invite/create", summary="Create Build Decision Book Invitations"
)
def build_decision_book_invite_create(
    request: Request, data: DecisionBookDecisionBookInvitations
):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@build_decision_book_route.post(
    path="/invite/update", summary="Update Build Decision Book Invitations"
)
def build_decision_book_invite_update(request: Request, data):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)
