import { useQuery } from "@tanstack/react-query";
import { queryKeys } from "./keys";
import { entitiesService } from "@/services";
import type { PaginationParams } from "@/types";

export function useEntities(params?: PaginationParams) {
  return useQuery({
    queryKey: queryKeys.entities.list(params),
    queryFn: () => entitiesService.list(params),
  });
}

export function useEntity(id: number) {
  return useQuery({
    queryKey: queryKeys.entities.detail(id),
    queryFn: () => entitiesService.getById(id),
    enabled: !!id,
  });
}

export function useEntityRoles(entityId: number) {
  return useQuery({
    queryKey: queryKeys.entities.roles(entityId),
    queryFn: () => entitiesService.getRoles(entityId),
    enabled: !!entityId,
  });
}
