import { expect, test } from "bun:test";
import { CHECKLIST } from "./checklist-data";
import { CATEGORY_ORDER } from "./types";

const EXPECTED: Record<string, number> = {
  foundations: 18,
  seo: 14,
  accessibility: 26,
  security: 17,
  "well-known": 10,
  "agent-readiness": 20,
  performance: 25,
  privacy: 7,
  resilience: 6,
  i18n: 13,
};

test("contains all 10 categories in order", () => {
  expect(CHECKLIST.map((c) => c.id)).toEqual(CATEGORY_ORDER);
});

test("each category has the expected item count, 156 total", () => {
  let total = 0;
  for (const cat of CHECKLIST) {
    expect(cat.items.length).toBe(EXPECTED[cat.id]);
    total += cat.items.length;
  }
  expect(total).toBe(156);
});

test("every item id is globally unique and well-formed", () => {
  const ids = new Set<string>();
  for (const cat of CHECKLIST) {
    for (const item of cat.items) {
      expect(item.id.startsWith(`${cat.id}/`)).toBe(true);
      expect(item.category).toBe(cat.id);
      expect(item.title.length).toBeGreaterThan(0);
      expect(item.url.startsWith("https://")).toBe(true);
      expect(ids.has(item.id)).toBe(false);
      ids.add(item.id);
    }
  }
  expect(ids.size).toBe(156);
});

test("every status is one of the four valid values", () => {
  const valid = new Set(["required", "recommended", "optional", "avoid"]);
  for (const cat of CHECKLIST) {
    for (const item of cat.items) {
      expect(valid.has(item.status)).toBe(true);
    }
  }
});
