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

export interface GetTaxonomyNodeAssignmentsInput {
  taxonomyNodeId: string;
}

export async function run(db: ReadonlyDB<DB>, input: GetTaxonomyNodeAssignmentsInput) {
  const assignments = await db
    .selectFrom("ItemTaxonomyAssignment")
    .selectAll()
    .where("taxonomyNodeId", "=", input.taxonomyNodeId)
    .execute();

  return ok({ assignments });
}
