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

from api_validations.validations_request import (
    InsertBuildParts,
    UpdateBuildParts,
    PatchRecord,
    ListOptions,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


build_parts_route = APIRouter(prefix="/building/parts", tags=["Building Parts"])
build_parts_route.include_router(build_parts_route, include_in_schema=True)


@build_parts_route.post(path="/list", summary="List Active/Delete/Confirm Build Parts")
def building_build_part_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_parts_route.post(
    path="/create", summary="Create Build Parts with given auth levels"
)
def building_build_part_create(request: Request, data: InsertBuildParts):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@build_parts_route.post(
    path="/update/{build_uu_id}", summary="Update Build Parts with given auth levels"
)
def building_build_part_update(
    request: Request, build_uu_id: str, data: UpdateBuildParts
):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, build_uu_id=build_uu_id, token_dict=token_dict
    )


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