import { describe, it, expect } from "vitest";
import {
  allradCode,
  normalizeCode,
  codesMatch,
  expandNameQuery,
} from "./codes";

describe("allradCode — eingeschobenes Allrad-A in die Abkürzung", () => {
  it('"HLF 3" -> "HLFA 3"', () => {
    expect(allradCode("HLF 3")).toBe("HLFA 3");
  });

  it('"MTF" -> "MTFA"', () => {
    expect(allradCode("MTF")).toBe("MTFA");
  });

  it('"HLF 1 W" -> "HLFA 1 W"', () => {
    expect(allradCode("HLF 1 W")).toBe("HLFA 1 W");
  });

  it("bereits Allrad bleibt unverändert: HLFA 2 -> HLFA 2", () => {
    expect(allradCode("HLFA 2")).toBe("HLFA 2");
  });
});

describe("normalizeCode — Grundform für Vergleiche (Allrad-Infix entfernt)", () => {
  it('"HLFA 3" -> "HLF 3"', () => {
    expect(normalizeCode("HLFA 3")).toBe("HLF 3");
  });

  it("trimmt und vereinheitlicht Leerzeichen + Großschreibung", () => {
    expect(normalizeCode("  hlf   3 ")).toBe("HLF 3");
  });

  it('"MTFA" -> "MTF"', () => {
    expect(normalizeCode("MTFA")).toBe("MTF");
  });
});

describe("codesMatch — Allrad-/Grundform sind gleich", () => {
  it('codesMatch("HLFA 3", "HLF 3") === true', () => {
    expect(codesMatch("HLFA 3", "HLF 3")).toBe(true);
  });

  it("verschiedene Codes matchen nicht", () => {
    expect(codesMatch("HLF 2", "HLF 3")).toBe(false);
  });
});

describe("expandNameQuery (bestehende Regel) bleibt intakt", () => {
  it('expandNameQuery("HLFA 1 W") enthält "HLF 1 W"', () => {
    expect(expandNameQuery("HLFA 1 W").nameLikes).toContain("HLF 1 W");
  });

  it('expandNameQuery("MTFA") enthält "MTF"', () => {
    expect(expandNameQuery("MTFA").nameLikes).toContain("MTF");
  });
});
