import { db, type TailorAnyDBField } from "@tailor-platform/sdk";
import { describe, it } from "vitest";
import type { CommonReservedFields, NoReservedFields } from "./entityTypes";

describe("NoReservedFields", () => {
  // A dummy model factory mirroring how db models apply the guard.
  const builtins = { name: db.string() };
  type ReservedFields = keyof typeof builtins | CommonReservedFields;

  function createDummyType<const F extends Record<string, TailorAnyDBField>>(params: {
    fields?: NoReservedFields<F, ReservedFields>;
  }) {
    return params;
  }

  it("rejects redefining a model-specific built-in field", () => {
    // @ts-expect-error -- "name" is a built-in field and cannot be redefined
    createDummyType({ fields: { name: db.string() } });
  });

  it("rejects redefining a common field (id / createdAt / updatedAt)", () => {
    createDummyType({
      fields: {
        // @ts-expect-error -- "id" is a built-in field and cannot be redefined
        id: db.string(),
        // @ts-expect-error -- "createdAt" is a built-in field and cannot be redefined
        createdAt: db.string(),
        // @ts-expect-error -- "updatedAt" is a built-in field and cannot be redefined
        updatedAt: db.string(),
      },
    });
  });

  it("accepts custom fields", () => {
    createDummyType({ fields: { customField: db.string() } });
  });
});
