import {
  macroBell,
  macroCwwe,
  macroGhz,
  macroLuna,
  macroSeal,
  macroTriangle,
  type Gate,
} from "./engine";

export type PresetGroup = "coin" | "planet";

export type Preset = {
  id: string;
  name: string;
  blurb: string;
  group: PresetGroup;
  nq: number;
  gates: Gate[];
};

const g = (t: Gate["t"], q: number, extra?: Partial<Gate>): Gate => ({ t, q, ...extra });

export const PRESETS: Preset[] = [
  { id: "bell", name: "Bell Pair", blurb: "(|00⟩ + |11⟩) / √2", group: "coin", nq: 2, gates: macroBell() },
  { id: "ghz", name: "GHZ State", blurb: "N-qubit star entanglement", group: "coin", nq: 4, gates: macroGhz(4) },
  { id: "tri", name: "Triangle", blurb: "1/9 · 4/9 · 9/9 closure", group: "coin", nq: 3, gates: macroTriangle() },
  { id: "cwwe", name: "CWWE Full", blurb: "Triangle plus gravity seal", group: "coin", nq: 4, gates: macroCwwe(4) },
  { id: "luna", name: "Luna Bridge", blurb: "6-qubit launch sequence", group: "coin", nq: 6, gates: macroLuna(6) },
  { id: "seal", name: "P3^Q Seal", blurb: "Governed phase on every wire", group: "coin", nq: 4, gates: macroSeal(4) },
  {
    id: "prov",
    name: "Proverbs 27",
    blurb: "Iron sharpens iron",
    group: "coin",
    nq: 4,
    gates: [
      g("H", 0),
      g("CNOT", 1, { c: 0 }),
      g("H", 2),
      g("CNOT", 3, { c: 2 }),
      g("CZ", 2, { c: 1 }),
      g("Rz", 0, { l: "seal" }),
      g("Rz", 3, { l: "seal" }),
    ],
  },
  {
    id: "au",
    name: "Au-197",
    blurb: "Z=79 delivery motif",
    group: "coin",
    nq: 4,
    gates: [
      g("H", 0),
      g("CNOT", 1, { c: 0 }),
      g("CNOT", 2, { c: 1 }),
      g("CNOT", 3, { c: 2 }),
      g("Rx", 1),
      g("Rz", 3, { l: "seal" }),
    ],
  },
  {
    id: "ward",
    name: "Wardenclyffe",
    blurb: "Seal of origin",
    group: "coin",
    nq: 4,
    gates: macroSeal(4),
  },
  {
    id: "echo",
    name: "Echo Operator",
    blurb: "E: Σ* → S*",
    group: "coin",
    nq: 4,
    gates: [
      g("H", 0),
      g("H", 1),
      g("H", 2),
      g("H", 3),
      g("CNOT", 2, { c: 3 }),
      g("CNOT", 1, { c: 2 }),
      g("CNOT", 0, { c: 1 }),
      g("Rz", 0, { l: "seal" }),
    ],
  },
  {
    id: "gan",
    name: "GaN-38",
    blurb: "Light scaffold",
    group: "coin",
    nq: 3,
    gates: [g("H", 0), g("Ry", 1), g("CNOT", 1, { c: 0 }), g("CNOT", 2, { c: 1 }), g("Rz", 2, { l: "π/φ" })],
  },
  {
    id: "te",
    name: "Te-52",
    blurb: "Temporal encryption motif",
    group: "coin",
    nq: 4,
    gates: [
      g("H", 0),
      g("Rz", 0, { l: "1/9" }),
      g("Rz", 1, { l: "4/9" }),
      g("Rz", 2, { l: "9/9" }),
      g("CNOT", 1, { c: 0 }),
      g("CZ", 3, { c: 2 }),
      g("Rz", 3, { l: "seal" }),
    ],
  },
  { id: "jupiter", name: "Jupiter", blurb: "Swarm star", group: "planet", nq: 5, gates: [...macroGhz(5), g("Rz", 4, { l: "seal" })] },
  { id: "saturn", name: "Saturn", blurb: "Ring of CZ", group: "planet", nq: 4, gates: [g("H", 0), g("H", 1), g("H", 2), g("H", 3), g("CZ", 1, { c: 0 }), g("CZ", 2, { c: 1 }), g("CZ", 3, { c: 2 }), g("CZ", 0, { c: 3 })] },
  { id: "moon", name: "Moon", blurb: "Launch bridge", group: "planet", nq: 6, gates: macroLuna(6) },
  { id: "neptune", name: "Neptune", blurb: "Deep Ry ladder", group: "planet", nq: 4, gates: [g("Ry", 0), g("Ry", 1), g("Ry", 2), g("Ry", 3), g("CNOT", 1, { c: 0 }), g("CNOT", 2, { c: 1 }), g("CNOT", 3, { c: 2 }), g("Rz", 3, { l: "seal" })] },
  { id: "earth", name: "Earth", blurb: "Home Bell", group: "planet", nq: 2, gates: macroBell() },
  { id: "mercury", name: "Mercury", blurb: "Short hop", group: "planet", nq: 2, gates: [g("H", 0), g("Rz", 0, { l: "π/φ" }), g("CNOT", 1, { c: 0 })] },
  { id: "venus", name: "Venus", blurb: "Paired Ry", group: "planet", nq: 3, gates: [g("Ry", 0), g("Ry", 1), g("CNOT", 1, { c: 0 }), g("CZ", 2, { c: 0 }), g("Rz", 2, { l: "4/9" })] },
  { id: "mars", name: "Mars", blurb: "Rx thrust", group: "planet", nq: 3, gates: [g("Rx", 0), g("H", 1), g("CNOT", 1, { c: 0 }), g("CNOT", 2, { c: 1 }), g("Rz", 2, { l: "seal" })] },
  { id: "pluto", name: "Pluto", blurb: "Edge seal", group: "planet", nq: 3, gates: macroSeal(3) },
  { id: "uranus", name: "Uranus", blurb: "Tilted axis", group: "planet", nq: 4, gates: [g("Rx", 0), g("Rz", 1, { l: "1/9" }), g("Ry", 2), g("H", 3), g("CNOT", 2, { c: 0 }), g("CZ", 3, { c: 1 })] },
];
