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

from api_validations.validations_request import (
    InsertAccountRecord,
    UpdateAccountRecord,
    SearchAddress,
    ListOptions,
    PatchRecord,
)

from api_services.redis.auth_actions.token import parse_token_object_to_dict


account_records_router = APIRouter(prefix="/account/records", tags=["Account Records"])
account_records_router.include_router(account_records_router, include_in_schema=True)


@account_records_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)


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


@account_records_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)


@account_records_router.post(
    path="/update/{address_uu_id}", summary="Update Address with given auth levels"
)
def address_update(request: Request, address_uu_id: str, data: UpdateAccountRecord):
    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
    )


@account_records_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
    )
