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

from api_validations.validations_request import (
    InsertUsers,
    UpdateUsers,
    PatchRecord,
    ListOptions,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


user_route = APIRouter(prefix="/user", tags=["User"])
user_route.include_router(user_route, include_in_schema=True)


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


@user_route.post(path="/create", summary="Create User with given auth levels")
def user_create(request: Request, data: InsertUsers):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@user_route.post(
    path="/update/{user_uu_id}", summary="Update User with given auth levels"
)
def user_update(request: Request, user_uu_id: str, data: UpdateUsers):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, user_uu_id=user_uu_id, token_dict=token_dict
    )


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