import { ok, type ReadonlyDB } from "@tailor-platform/erp-kit/core";
import type { DB } from "../generated/kysely-tailordb";

export interface GetTaxonomyNodeChildrenInput {
  parentId: string;
}

export async function run(db: ReadonlyDB<DB>, input: GetTaxonomyNodeChildrenInput) {
  const children = await db
    .selectFrom("TaxonomyNode")
    .selectAll()
    .where("parentId", "=", input.parentId)
    .execute();

  return ok({ children });
}
