import { describe, expect, it } from "vitest";
import { buildIkScanCapabilityRows } from "./ikScanCapabilities";
import type { NativeScannerDataStatus } from "../types/global";

function validData(overrides: Partial<NativeScannerDataStatus> = {}): NativeScannerDataStatus {
  return {
    directory: "C:/app/data/ik-inventorylists",
    version: "6.7.0",
    artifactSets: 61,
    artifactPieces: 289,
    weapons: 247,
    characters: 119,
    materials: 715,
    totalEntries: 1370,
    categories: {
      artifacts: {
        file: "artifacts.json",
        setCount: 61,
        pieceCount: 289,
        supported: true,
        catalogAvailable: true,
        nativeCaptureSupported: true,
        scanStatus: "native_capture",
      },
      weapons: {
        file: "weapons.json",
        count: 247,
        supported: false,
        catalogAvailable: true,
        nativeCaptureSupported: false,
        scanStatus: "catalog_only",
      },
      characters: {
        file: "characters.json",
        count: 119,
        supported: false,
        catalogAvailable: true,
        nativeCaptureSupported: false,
        scanStatus: "catalog_only",
      },
      materials: {
        file: "materials.json",
        count: 715,
        supported: false,
        catalogAvailable: true,
        nativeCaptureSupported: false,
        scanStatus: "catalog_only",
      },
    },
    missing: [],
    valid: true,
    source: "InventoryKamera inventorylists",
    ...overrides,
  };
}

describe("IK scan capabilities", () => {
  it("marks artifacts as native capture and other IK categories as catalog-only", () => {
    const rows = buildIkScanCapabilityRows(validData());

    expect(rows).toEqual([
      expect.objectContaining({
        id: "artifacts",
        countLabel: "61/289",
        status: "native_capture",
        statusLabel: "Native Capture",
        className: "ok",
      }),
      expect.objectContaining({
        id: "weapons",
        countLabel: "247",
        status: "catalog_only",
        statusLabel: "Katalog bereit",
        className: "muted",
      }),
      expect.objectContaining({
        id: "characters",
        countLabel: "119",
        status: "catalog_only",
      }),
      expect.objectContaining({
        id: "materials",
        countLabel: "715",
        status: "catalog_only",
      }),
    ]);
  });

  it("keeps every category unsafe when the IK inventorylists are incomplete", () => {
    const rows = buildIkScanCapabilityRows(validData({ valid: false, missing: ["materials.json"] }));

    expect(rows).toHaveLength(4);
    expect(rows.every((row) => row.status === "missing_data")).toBe(true);
    expect(rows.every((row) => row.className === "warn")).toBe(true);
  });
});
