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

from api_validations.validations_request import (
    InsertDuties,
    UpdateDuties,
    SelectDuties,
    PatchRecord,
    ListOptions,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


duties_route = APIRouter(prefix="/duties", tags=["Duties"])
duties_route.include_router(duties_route, include_in_schema=True)


@duties_route.post(path="/list", summary="List Active/Delete/Confirm Duties")
def company_duties_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)


@duties_route.post(path="/get_by_duty_uuid", summary="Get Single Duty by Duty UUID")
def company_duties_get_by_duty_uuid(request: Request, data: SelectDuties):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@duties_route.post(path="/create", summary="Create Duties with given auth levels")
def company_duties_create(request: Request, data: InsertDuties):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@duties_route.post(
    path="/update/{duties_uu_id}", summary="Update Duties with given auth levels"
)
def company_duties_update(request: Request, duties_uu_id: str, data: UpdateDuties):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, duties_uu_id=duties_uu_id, token_dict=token_dict
    )


@duties_route.patch(
    path="/patch/{duties_uu_id}", summary="Patch Duties with given auth levels"
)
def company_duties_patch(request: Request, duties_uu_id: str, data: PatchRecord):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, duties_uu_id=duties_uu_id, token_dict=token_dict
    )
