// QR Scanner Service Types

/**
 * Listener interface for QR code scan events
 */
export interface ScanListener {
  /** Called when a QR code is successfully scanned */
  onScan: (result: string) => void;
  /** Called when an error occurs during scanning */
  onError?: (error: Error) => void;
}

/**
 * Options for configuring the QR scanner
 */
export interface QRScannerOptions {
  /** Camera to use ('front' or 'back') */
  camera?: "front" | "back";
  /** Whether to show a preview of the camera feed */
  showPreview?: boolean;
  /** Whether to play a sound on successful scan */
  playSound?: boolean;
}

export type CameraState =
  | "initializing" // Camera is being initialized
  | "ready" // Camera is ready to use
  | "active" // Camera is actively streaming
  | "in_use" // Camera is in use by another application
  | "permission_denied" // Camera permission was denied
  | "not_found" // No camera found on device
  | "error" // Generic error state
  | "off"; // Camera is off/stopped

export interface CameraStateListener {
  onStateChange: (state: CameraState, message?: string) => void;
}

/**
 * Interface for QR scanner service implementations
 */
export interface QRScannerService {
  /** Check if camera permissions are granted */
  checkPermissions(): Promise<boolean>;

  /** Request camera permissions from the user */
  requestPermissions(): Promise<boolean>;

  /** Check if QR scanning is supported on this device */
  isSupported(): Promise<boolean>;

  /** Start scanning for QR codes */
  startScan(options?: QRScannerOptions): Promise<void>;

  /** Stop scanning for QR codes */
  stopScan(): Promise<void>;

  /** Add a listener for scan events */
  addListener(listener: ScanListener): void;

  /** Add a listener for camera state changes */
  addCameraStateListener(listener: CameraStateListener): void;

  /** Remove a camera state listener */
  removeCameraStateListener(listener: CameraStateListener): void;

  /** Clean up scanner resources */
  cleanup(): Promise<void>;
}
