import type { AppSnapshot } from "../../types/domain";
import type { BooleanResult, CaptureOptions, CaptureResult, CaptureSourceInfo, RuntimeInfo, ReviewSampleRecord } from "../../types/global";
import type { AutoScanStats, ScanSummary } from "../../lib/scannerSession";
import type { ParsedArtifactCandidate } from "../../lib/artifactOcrParser";
import type { ScannerLearningRules } from "../../lib/scannerLearning";
import type { Dispatch, SetStateAction } from "react";
import type { analyzeReviewSamples } from "../../lib/reviewSampleAnalysis";

export interface ScanViewProps {
  snapshot: AppSnapshot;
  isScanning: boolean;
  captureSources: CaptureSourceInfo[];
  selectedSourceId: string;
  setSelectedSourceId: (value: string) => void;
  latestCapture: CaptureResult | null;
  captureStatus: string;
  refreshCaptureSources: () => Promise<void>;
  captureSelectedSource: (delayMs?: number, focusGenshin?: boolean, options?: CaptureOptions) => Promise<CaptureResult | null>;
  bridgeReady: boolean;
  onStoredArtifactsChanged?: () => Promise<void>;
}

export interface ScanViewControllerResult {
  detailsOpen: boolean;
  diagnosticsOpen: boolean;
  settingsOpen: boolean;
  reviewQueueOpen: boolean;
  reviewSamples: ReviewSampleRecord[];
  reviewSampleTotal: number;
  reviewStatus: string;
  autoScanRunning: boolean;
  autoScanStats: AutoScanStats;
  scanSummary: ScanSummary | null;
  scanLimit: number;
  scanLimitTouched: boolean;
  skipRows: number;
  automationLog: string[];
  storedTotal: number | null;
  devMode: boolean;
  scannerLearningRules: ScannerLearningRules;
  learningRulesLoaded: boolean;
  runtimeInfo: RuntimeInfo | null;
  parsedArtifact: ParsedArtifactCandidate | null;
  reviewAnalysis: ReturnType<typeof analyzeReviewSamples>;
  learningRuleCount: number;
  detectedInventoryCount: number;
  scanProgressPercent: number;
  activeTargetCount: number;
  requiresAdminForAutoScan: boolean;
  hasSourceSelected: boolean;
  canCaptureSource: boolean;
  canReadReviewQueue: boolean;
  canSaveReviewSample: boolean;
  canAutoScan: boolean;
  scannerModeLabel: string;
  sourceLabel: string;
  gridLabel: string;
  inventoryLabel: string;
  selectedSource: CaptureSourceInfo | undefined;
  genshinSource: CaptureSourceInfo | undefined;

  setDetailsOpen: Dispatch<SetStateAction<boolean>>;
  setDiagnosticsOpen: Dispatch<SetStateAction<boolean>>;
  setSettingsOpen: Dispatch<SetStateAction<boolean>>;
  setReviewQueueOpen: Dispatch<SetStateAction<boolean>>;
  setScanSummary: Dispatch<SetStateAction<ScanSummary | null>>;
  setScanLimit: Dispatch<SetStateAction<number>>;
  setScanLimitTouched: Dispatch<SetStateAction<boolean>>;
  setSkipRows: Dispatch<SetStateAction<number>>;

  toggleDevMode: () => void;
  requestScanStop: (reason?: string) => void;
  saveReviewSample: (
    capture?: CaptureResult | null,
    parsed?: ParsedArtifactCandidate | null,
    reason?: string,
  ) => Promise<BooleanResult | null>;
  loadReviewQueue: () => Promise<void>;
  openReviewQueue: () => Promise<void>;
  runAutoReviewScan: () => Promise<void>;
  runVisibleGridScan: () => Promise<void>;
}
