import { t } from "@tailor-platform/sdk";
import { defineSchema } from "@tailor-platform/sdk/seed";
import { createTailorDBHook, createStandardSchema } from "@tailor-platform/sdk/test";
import { productAttributeAssignment } from "../../src/modules-db";

const schemaType = t.object({
  ...productAttributeAssignment.pickFields(["id","createdAt"], { optional: true }),
  ...productAttributeAssignment.omitFields(["id","createdAt"]),
});

const hook = createTailorDBHook(productAttributeAssignment);

export const schema = defineSchema(
  createStandardSchema(schemaType, hook),
  {
    foreignKeys: [
      {"column":"productId","references":{"table":"Product","column":"id"}},
      {"column":"attributeId","references":{"table":"ProductAttribute","column":"id"}},
      {"column":"valueId","references":{"table":"ProductAttributeValue","column":"id"}},
    ],
    indexes: [
      {"name":"product_attribute_assignment_unique_idx","columns":["productId","attributeId","valueId"],"unique":true},
    ],
  }
);
