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

export interface ListAttributeAssignmentsByAttributeInput {
  attributeId: string;
}

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

  return ok({ assignments });
}
