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

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

const hook = createTailorDBHook(rolePermission);

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