from typing import Any
from fastapi import APIRouter, Depends

from index import endpoints_index
from events.account_records.cluster import AccountRecordsRouterCluster

from api_validations.defaults.validations import CommonHeaders
from api_validations.response.pagination import PaginateOnly
from api_middlewares.token_provider import TokenProvider


account_records_router = APIRouter(prefix="/account/records", tags=["Account Cluster"])


account_records_list = "AccountRecordsList"
@account_records_router.post(
    path="/list",
    description="List all account records endpoint",
    operation_id=endpoints_index[account_records_list],
)
def people_list_route(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
    token_object = TokenProvider.get_dict_from_redis(token=headers.token)
    event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
    event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
    FoundCluster = AccountRecordsRouterCluster.get_event_cluster(account_records_list)
    event_cluster_matched = FoundCluster.match_event(event_key=event_key)
    return event_cluster_matched.event_callable(list_options=data, header=headers)


account_records_create = "AccountRecordsCreate"
@account_records_router.post(
    path="/create",
    description="Create account records endpoint",
    operation_id=endpoints_index[account_records_create],
)
def account_records_create_route(data, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
    token_object = TokenProvider.get_dict_from_redis(token=headers.token)
    event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
    event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
    FoundCluster = AccountRecordsRouterCluster.get_event_cluster(account_records_create)
    event_cluster_matched = FoundCluster.match_event(event_key=event_key)
    return event_cluster_matched.event_callable(data=data, header=headers)


account_records_update = "AccountRecordsUpdate"
@account_records_router.post(
    path="/update/{uu_id}",
    description="Update account records endpoint",
    operation_id=endpoints_index[account_records_update],
)
def account_records_update_route(uu_id: str, data, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
    token_object = TokenProvider.get_dict_from_redis(token=headers.token)
    event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
    event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
    FoundCluster = AccountRecordsRouterCluster.get_event_cluster(account_records_update)
    event_cluster_matched = FoundCluster.match_event(event_key=event_key)
    return event_cluster_matched.event_callable(uu_id=uu_id, data=data, header=headers)


account_records_delete = "AccountRecordsDelete"
@account_records_router.post(
    path="/delete/{uu_id}",
    description="Delete account records endpoint",
    operation_id=endpoints_index[account_records_delete],
)
def account_records_delete_route(uu_id: str, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
    token_object = TokenProvider.get_dict_from_redis(token=headers.token)
    event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
    event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
    FoundCluster = AccountRecordsRouterCluster.get_event_cluster(account_records_delete)
    event_cluster_matched = FoundCluster.match_event(event_key=event_key)
    return event_cluster_matched.event_callable(uu_id=uu_id, header=headers)
