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

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

const hook = createTailorDBHook(item);

export const schema = defineSchema(
  createStandardSchema(schemaType, hook),
  {
    foreignKeys: [
      {"column":"unitId","references":{"table":"Unit","column":"id"}},
    ],
    indexes: [
      {"name":"item_sku_unique_idx","columns":["sku"],"unique":true},
      {"name":"item_barcode_unique_idx","columns":["barcode"],"unique":true},
    ],
  }
);
