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

from api_validations.validations_request import (
    PatchRecord,
    ListOptions,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


services_route = APIRouter(prefix="/services", tags=["Services"])
services_route.include_router(services_route, include_in_schema=True)


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


@services_route.post(path="/create", summary="Create Modules with given auth levels")
def services_create(request: Request, data):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@services_route.post(
    path="/update/{service_uu_id}", summary="Update Modules with given auth levels"
)
def services_update(request: Request, service_uu_id: str, data):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, service_uu_id=service_uu_id, token_dict=token_dict
    )


@services_route.patch(
    path="/patch/{service_uu_id}", summary="Patch Modules with given auth levels"
)
def services_patch(request: Request, service_uu_id: str, data: PatchRecord):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, service_uu_id=service_uu_id, token_dict=token_dict
    )
