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

from api_validations.validations_request import (
    InsertAddress,
    UpdateAddress,
    SearchAddress,
    ListOptions,
    PatchRecord,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


address_router = APIRouter(prefix="/address", tags=["Address"])
address_router.include_router(address_router, include_in_schema=True)


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


@address_router.post(path="/create", summary="Create Address with given auth levels")
def address_create(request: Request, data: InsertAddress):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@address_router.post(path="/search", summary="Search Address with given auth levels")
def address_search(request: Request, data: SearchAddress):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(data=data, token_dict=token_dict)


@address_router.post(
    path="/update/{address_uu_id}", summary="Update Address with given auth levels"
)
def address_update(request: Request, address_uu_id: str, data: UpdateAddress):
    token_dict = parse_token_object_to_dict(request=request)
    return token_dict.available_event(
        data=data, address_uu_id=address_uu_id, token_dict=token_dict
    )


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