export interface StoredArtifactRecord {
  id: string;
  name: string;
  slot: string;
  level?: number;
  setName: string;
  mainStat: string;
  mainValue: string;
  substats: string[];
  equipped: string;
  confidence: number;
  needsReview: boolean;
  locked?: boolean;
  source: string;
  firstSeenAt?: string;
  lastSeenAt?: string;
  timesSeen?: number;
}

export type ScanResultCategory = "artifact" | "weapon" | "character" | "material" | "unknown";

export type ScanResultExtractionStatus =
  | "parsed"
  | "review"
  | "missing_crop"
  | "parse_error"
  | "error";

export type ArtifactValueStatus =
  | "deferred"
  | "review";

export interface ScanResultArtifactIdentity {
  name: string;
  slot: string;
  level?: number;
  setName: string;
  mainStat: string;
  mainValue: string;
  substats: string[];
  equipped: string;
  locked?: boolean;
}

export interface ScanResultIkMatch {
  matched: boolean;
  confidence: number;
  source: "ik-inventorylists";
  setKey?: string;
  setGood?: string;
  setName?: string;
  artifactKey?: string;
  artifactGood?: string;
  artifactName?: string;
  slotKey?: string;
  notes: string[];
}

export interface ScanResultFieldConfidence {
  key: string;
  label: string;
  value: string;
  confidence: number;
  source: "ocr" | "database" | "derived" | "fallback" | "missing";
}

export interface StoredScanResultEntry {
  id: string;
  runId: string;
  sequence: number;
  page?: number;
  row?: number;
  col?: number;
  category: ScanResultCategory;
  source: string;
  imagePath: string;
  capturedAt: string;
  extractionStatus: ScanResultExtractionStatus;
  extractionConfidence: number;
  needsReview: boolean;
  valueStatus: ArtifactValueStatus;
  valueScore: number | null;
  artifact?: ScanResultArtifactIdentity;
  ikMatch?: ScanResultIkMatch;
  fieldConfidences?: ScanResultFieldConfidence[];
  artifactRecordId?: string;
  persistedArtifact: boolean;
  notes: string[];
  error?: string;
  review?: {
    status: "approved" | "rejected";
    reviewedAt: string;
    note?: string;
    correctedFields: string[];
  };
}
