import test from "node:test";
import assert from "node:assert/strict";
import schema from "../frontend/schemeta.schema.json" with { type: "json" };

test("schema keeps streamlined symbol shorthand support", () => {
  const symbol = schema?.$defs?.symbol;
  assert.ok(symbol);
  assert.deepEqual(symbol.required, []);
  assert.equal(symbol.properties.template_name.type, "string");
  assert.ok(Array.isArray(symbol.examples));
  assert.ok(symbol.examples.some((v) => v.template_name === "resistor"));
  assert.ok(symbol.examples.some((v) => v.category === "generic"));
});

test("schema supports built-in instance.part shortcuts without explicit symbols", () => {
  const instance = schema?.$defs?.instance;
  assert.ok(instance);
  assert.ok(Array.isArray(instance.anyOf));
  assert.ok(instance.anyOf.some((rule) => Array.isArray(rule.required) && rule.required.includes("symbol")));
  assert.ok(instance.anyOf.some((rule) => Array.isArray(rule.required) && rule.required.includes("part")));

  const partEnum = instance.properties?.part?.enum ?? [];
  assert.ok(partEnum.includes("resistor"));
  assert.ok(partEnum.includes("capacitor"));
  assert.ok(partEnum.includes("generic"));
});

test("schema preserves per-pin UI edit metadata contract", () => {
  const pinUi = schema?.$defs?.instance?.properties?.properties?.properties?.pin_ui;
  assert.ok(pinUi);
  const pinUiEntry = pinUi.additionalProperties;
  assert.ok(pinUiEntry);
  assert.equal(pinUiEntry.properties.show_net_label.type, "boolean");
});
