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

from api_validations.validations_request import (
    InsertCompany,
    UpdateCompany,
    PatchRecord,
    ListOptions,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


company_route = APIRouter(prefix="/company", tags=["Company"])
company_route.include_router(company_route, include_in_schema=True)


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


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


@company_route.post(
    path="/update/{company_uu_id}", summary="Update Company with given auth levels"
)
def company_company_update(request: Request, company_uu_id: str, data: UpdateCompany):
    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
    )


@company_route.patch(
    path="/patch/{company_uu_id}", summary="Update Active/Delete/Confirm"
)
def company_company_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
    )
