import type {
  AutomationGuard,
  CaptureOptions,
  CaptureResult,
  CaptureSourceInfo,
  ClickResult,
  ArtifactStoreLoadResult,
  ArtifactStoreSaveResult,
  ReviewSampleListResult,
  ReviewSamplePayload,
  LoadScannerLearningRulesResult,
  SaveScannerLearningRulesResult,
  SaveResultWithPath,
  FocusGenshinResult,
  RuntimeInfo,
  BooleanResult,
  ScrollResult,
  ScannerStatusPayload,
  ScannerLearningRulePayload,
} from "../../src/types/global.js";
import type { StoredArtifactRecord } from "../../src/types/storage.js";
import type { AppSnapshot } from "../../src/types/domain.js";

export type {
  ArtifactStoreLoadResult,
  ArtifactStoreSaveResult,
  ReviewSampleListResult,
  ReviewSamplePayload,
  LoadScannerLearningRulesResult,
  SaveScannerLearningRulesResult,
} from "../../src/types/global.js";

export interface ArtifactStoreRepositoryPort {
  loadAll(): Promise<ArtifactStoreLoadResult>;
  loadMap(): Promise<Map<string, StoredArtifactRecord>>;
  saveMany(records: StoredArtifactRecord[]): Promise<ArtifactStoreSaveResult>;
}

export interface ReviewSamplesRepositoryPort {
  list(limit?: number): Promise<ReviewSampleListResult>;
  append(sample: ReviewSamplePayload): Promise<SaveResultWithPath>;
}

export type ScannerLearningRules = ScannerLearningRulePayload;
export interface ScannerLearningLoadResult extends LoadScannerLearningRulesResult {}
export interface ScannerLearningSaveResult extends SaveScannerLearningRulesResult {}

export interface ScannerLearningRepositoryPort {
  load(): Promise<ScannerLearningLoadResult>;
  save(rules: ScannerLearningRules): Promise<ScannerLearningSaveResult>;
}

export interface SnapshotRepositoryPort {
  load(): Promise<AppSnapshot | null>;
  save(snapshot: AppSnapshot): Promise<SaveResultWithPath>;
}

export interface RuntimeRepositoryPort {
  focusMainWindow(): Promise<BooleanResult>;
  moveMainWindowOffGenshin(): Promise<void>;
  focusGenshinForScanStart(): Promise<FocusGenshinResult>;
  publishScannerStatus(status: ScannerStatusPayload): Promise<BooleanResult>;
  getRuntimeInfo(): Promise<RuntimeInfo>;
  showOverlay: () => Promise<BooleanResult>;
  hideOverlay: () => Promise<BooleanResult>;
}

export interface AutomationRepositoryPort {
  getAutomationGuard(): Promise<AutomationGuard>;
  clickScreen(x: number, y: number): Promise<ClickResult>;
  scrollScreen(notches: number, anchorX?: number, anchorY?: number): Promise<ScrollResult>;
}

export interface CaptureRepositoryPort {
  listSources(): Promise<CaptureSourceInfo[]>;
  captureSource(sourceId: string, delayMs?: number, focusGenshin?: boolean, options?: CaptureOptions): Promise<CaptureResult>;
}
