import { useMemo } from "react";
import {
  getTaxonomyV1,
  findById,
  findByPath,
  getLeaves,
  getParentById,
  type Taxonomy,
  type TaxonomyNode,
  type TaxonomyLeaf,
} from "../services/categoryTaxonomyService";

export interface UseCategoryTaxonomyResult {
  taxonomy: Taxonomy;
  findById: (id: number) => TaxonomyNode | null;
  findByPath: (path: string[]) => TaxonomyNode | null;
  getLeaves: () => TaxonomyLeaf[];
  getParentById: (id: number) => TaxonomyNode | null;
}

export function useCategoryTaxonomy(): UseCategoryTaxonomyResult {
  return useMemo<UseCategoryTaxonomyResult>(
    () => ({
      taxonomy: getTaxonomyV1(),
      findById,
      findByPath,
      getLeaves,
      getParentById,
    }),
    [],
  );
}
