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

export interface GetProductAttributeAssignmentInput {
  productId: string;
  attributeId: string;
}

export async function run(db: ReadonlyDB<DB>, input: GetProductAttributeAssignmentInput) {
  const assignments = await db
    .selectFrom("ProductAttributeAssignment")
    .selectAll()
    .where("productId", "=", input.productId)
    .where("attributeId", "=", input.attributeId)
    .execute();

  return ok({ assignments });
}
