import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";

export type Band = "clean" | "mold";

export type Sample = {
  /** Curated fixture image file name. */
  file: string;
  label: string;
  /** Expected classification band for this image. */
  band: Band;
  /** Realistic raw model JSON for this image, before normalization. */
  raw: Record<string, unknown>;
};

export function imageDataUrl(file: string) {
  const path = fileURLToPath(new URL(`./fixtures/${file}`, import.meta.url));
  return `data:image/png;base64,${readFileSync(path).toString("base64")}`;
}

const LOW_ENV = {
  ventilation: "Low",
  humidity: "Low",
  condensation: "Low",
  leakage: "Low",
  dampness: "Low",
  airCirculation: "Low",
  structuralMoisture: "Low",
};

export const SAMPLES: Sample[] = [
  {
    file: "clean-wall.png",
    label: "Clean painted wall",
    band: "clean",
    raw: {
      moldScore: 8,
      imageQuality: "Good",
      verdict: "No visible mold",
      confidence: 90,
      severity: "Low",
      evidence: ["Painted wall surface appears clean and dry"],
      factors: [],
      recommendations: ["Continue routine monitoring"],
      summary: "No visible mold growth, moisture staining or water damage is present.",
      environmental: LOW_ENV,
      leakage: { verdict: "No obvious signs detected", signs: [] },
      detections: [],
    },
  },
  {
    // Regression case: absence wording ("no mold, no staining") must not be read as evidence.
    file: "clean-ceiling.png",
    label: "Clean ceiling corner described with negations",
    band: "clean",
    raw: {
      moldScore: 62,
      imageQuality: "Fair",
      verdict: "Possible mold growth",
      confidence: 84,
      severity: "Medium",
      evidence: ["There are no dark stains, no discolouration and no damp patches on the ceiling"],
      factors: ["Bathroom environment"],
      recommendations: ["Further inspection recommended"],
      summary: "There are no visible signs of mold growth, moisture staining or water damage.",
      environmental: { ...LOW_ENV, humidity: "High" },
      leakage: { verdict: "No obvious signs detected", signs: [] },
      detections: [{ imageIndex: 0, kind: "mold", moldDetected: "No", severity: "Low", confidence: 40 }],
    },
  },
  {
    file: "stained-bathroom-ceiling.png",
    label: "Dark spotting on a bathroom ceiling",
    band: "mold",
    raw: {
      moldScore: 30,
      imageQuality: "Fair",
      verdict: "Possible moisture staining",
      confidence: 45,
      severity: "Low",
      evidence: ["Dark brown and black speckled staining across the bathroom ceiling", "Condensation sheen"],
      factors: ["Poor ventilation", "Shower humidity"],
      recommendations: ["Arrange a professional inspection"],
      summary: "Dark spotting is visible on the bathroom ceiling above the shower.",
      environmental: { ...LOW_ENV, humidity: "High", condensation: "High" },
      leakage: { verdict: "Possible leakage detected", signs: ["Ceiling discoloration"] },
      detections: [
        {
          imageIndex: 0,
          kind: "mold",
          moldDetected: "Possible",
          severity: "Medium",
          confidence: 70,
          surface: "painted plaster ceiling",
          box: { x: 0.2, y: 0.2, w: 0.4, h: 0.35 },
        },
      ],
    },
  },
  {
    file: "damp-wall-patch.png",
    label: "Damp patch with peeling paint at skirting level",
    band: "mold",
    raw: {
      moldScore: 78,
      imageQuality: "Good",
      verdict: "Likely mold growth",
      confidence: 99,
      severity: "High",
      evidence: ["Large damp patch with tide marks", "Bubbling and peeling paint along the lower wall"],
      factors: ["Rising damp", "Long-term moisture exposure"],
      recommendations: ["Professional inspection and treatment recommended"],
      summary: "A large damp patch with peeling paint indicates long-term moisture exposure.",
      environmental: { ...LOW_ENV, dampness: "High", structuralMoisture: "High" },
      leakage: { verdict: "Strong indication of moisture damage", signs: ["Damp patches", "Peeling paint"] },
      detections: [
        {
          imageIndex: 0,
          kind: "moisture",
          moldDetected: "Yes",
          severity: "High",
          confidence: 88,
          box: { x: 0.1, y: 0.5, w: 0.8, h: 0.4 },
        },
      ],
    },
  },
];
