import { describe, it, expect } from "vitest";
import type { CollectionRetention, PurgeSchedule } from "./retention-types";

describe("CollectionRetention type safety", () => {
  it("accepts a minimal CollectionRetention with only purgeSchedule", () => {
    const minimal: CollectionRetention = { purgeSchedule: "daily" };
    expect(minimal.purgeSchedule).toBe("daily");
    expect(minimal.activeRetention).toBeUndefined();
    expect(minimal.postDeletion).toBeUndefined();
    expect(minimal.coldArchive).toBeUndefined();
  });

  it("accepts a full CollectionRetention", () => {
    const full: CollectionRetention = {
      purgeSchedule: "weekly",
      activeRetention: { duration: "P2Y", trigger: "from-last-access" },
      postDeletion: {
        duration: "P30D",
        trigger: "after-deletion",
        action: "pseudonymize",
      },
      coldArchive: { duration: "P7Y", trigger: "from-creation" },
    };
    expect(full.activeRetention?.duration).toBe("P2Y");
    expect(full.postDeletion?.action).toBe("pseudonymize");
    expect(full.coldArchive?.duration).toBe("P7Y");
  });

  it("accepts a cron expression as PurgeSchedule via string extension", () => {
    const schedule: PurgeSchedule = "0 3 * * 0";
    expect(schedule).toBe("0 3 * * 0");
  });

  it("rejects CollectionRetention missing required purgeSchedule at compile time", () => {
    // @ts-expect-error — 'purgeSchedule' is required
    const _missing: CollectionRetention = {
      activeRetention: { duration: "P1Y", trigger: "from-creation" },
    };
    void _missing;
  });
});
