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

from api_validations.validations_request import (
    InsertCompanyDuty,
    PatchRecord,
    ListOptions,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


duty_route = APIRouter(prefix="/duty", tags=["Duty"])
duty_route.include_router(duty_route, include_in_schema=True)


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


@duty_route.post(path="/create", summary="Create Company with given auth levels")
def company_duty_create(request: Request, data: InsertCompanyDuty):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@duty_route.post(
    path="/update/{company_uu_id}", summary="Update Company with given auth levels"
)
def company_duty_update(request: Request, company_uu_id: str, data):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, company_uu_id=company_uu_id, token_dict=token_dict
    )


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