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

export interface GetProductCategoryAssignmentInput {
  productId: string;
  categoryId: string;
}

export async function run(db: ReadonlyDB<DB>, input: GetProductCategoryAssignmentInput) {
  const assignment = await db
    .selectFrom("ProductCategoryAssignment")
    .selectAll()
    .where("productId", "=", input.productId)
    .where("categoryId", "=", input.categoryId)
    .executeTakeFirst();

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