from typing import Any
from fastapi import APIRouter, Depends

from index import endpoints_index
from events.people.cluster import PeopleRouterCluster

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


people_endpoint_route = APIRouter(prefix="/people", tags=["People Cluster"])


people_list = "PeopleList"
@people_endpoint_route.post(
    path="/list",
    description="List all people endpoint",
    operation_id=endpoints_index[people_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 = PeopleRouterCluster.get_event_cluster(people_list)
    event_cluster_matched = FoundCluster.match_event(event_key=event_key)
    return event_cluster_matched.event_callable(list_options=data, headers=headers)


people_create = "PeopleCreate"
@people_endpoint_route.post(
    path="/create",
    description="Create people endpoint",
    operation_id=endpoints_index[people_create],
)
def people_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 = PeopleRouterCluster.get_event_cluster(people_create)
    event_cluster_matched = FoundCluster.match_event(event_key=event_key)
    return event_cluster_matched.event_callable(data=data, headers=headers)


people_update = "PeopleUpdate"
@people_endpoint_route.post(
    path="/update/{uu_id}",
    description="Update people endpoint",
    operation_id=endpoints_index[people_update],
)
def people_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 = PeopleRouterCluster.get_event_cluster(people_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)


people_delete = "PeopleDelete"
@people_endpoint_route.delete(
    path="/delete/{uu_id}",
    description="Delete people endpoint",
    operation_id=endpoints_index[people_delete],
)
def people_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 = PeopleRouterCluster.get_event_cluster(people_delete)
    event_cluster_matched = FoundCluster.match_event(event_key=event_key)
    return event_cluster_matched.event_callable(uu_id=uu_id, headers=headers)
