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

from api_validations.validations_request import (
    InsertPostCode,
    UpdatePostCode,
    ListOptions,
    PatchRecord,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


post_code_router = APIRouter(prefix="/postcode", tags=["Post Code"])
post_code_router.include_router(post_code_router, include_in_schema=True)


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


@post_code_router.post(path="/create", summary="Create PostCode with given auth levels")
def post_code_create(request: Request, data: InsertPostCode):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@post_code_router.post(
    path="/update/{post_code_uu_id}", summary="Update PostCode with given auth levels"
)
def post_code_update(request: Request, post_code_uu_id: str, data: UpdatePostCode):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, post_code_uu_id=post_code_uu_id, token_dict=token_dict
    )


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