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

export interface GetItemTaxonomyAssignmentInput {
  itemId: string;
  taxonomyNodeId: string;
}

export async function run(db: ReadonlyDB<DB>, input: GetItemTaxonomyAssignmentInput) {
  const assignment = await db
    .selectFrom("ItemTaxonomyAssignment")
    .selectAll()
    .where("itemId", "=", input.itemId)
    .where("taxonomyNodeId", "=", input.taxonomyNodeId)
    .executeTakeFirst();

  return ok({ assignment: assignment ?? null });
}
