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

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

const hook = createTailorDBHook(userRole);

export const schema = defineSchema(
  createStandardSchema(schemaType, hook),
  {
    foreignKeys: [
      {"column":"userId","references":{"table":"User","column":"id"}},
      {"column":"roleId","references":{"table":"Role","column":"id"}},
    ],
    indexes: [
      {"name":"user_role_unique_idx","columns":["userId","roleId"],"unique":true},
    ],
  }
);
