/**
 * This file contains all the TypeScript interfaces for the ML detection system.
 */

/**
 * Configuration for the detection engine.
 */
export interface DetectionConfig {
  frameSkip: number;
  confidenceThreshold: number;
  modelVariant: 'quantized' | 'standard' | 'full';
  maxDetections: number;
  inputSize: [number, number];
  enableContinuous: boolean;
  enableTrigger: boolean;
}

/**
 * Information about a specific model variant.
 */
export interface ModelInfo {
  variant: 'quantized' | 'standard' | 'full';
  url: string;
  size: number; // in bytes
  name: string;
  description: string;
}

/**
 * Represents a single detected object.
 */
export interface DetectionResult {
  bbox: [number, number, number, number]; // [x, y, width, height]
  confidence: number;
  class: string;
}

/**
 * Defines the performance tier of the user's device.
 */
export type DeviceTier = 'low' | 'mid' | 'high';

/**
 * Holds information about the device's capabilities.
 */
export interface DeviceCapabilities {
  tier: DeviceTier;
  hasWebGL: boolean;
  cpuCores: number;
  memory: number; // in GB
}

/**
 * Performance metrics for the detection engine.
 */
export interface DetectionMetrics {
  fps: number;
  inferenceTime: number;
  memoryUsage: number; // in MB
}

/**
 * Types for messages sent to and from the detection worker.
 */
export type WorkerMessage =
  | { type: 'INITIALIZE' }
  | { type: 'DETECT'; imageData: ImageData }
  | { type: 'UPDATE_CONFIG'; config: DetectionConfig }
  | { type: 'LOAD_MODEL'; variant: 'quantized' | 'standard' | 'full'; modelData: ArrayBuffer }
  | { type: 'CONFIGURE'; config: DetectionConfig };

export type WorkerResponse =
  | { type: 'INITIALIZED' }
  | { type: 'DETECTION_RESULT'; result: DetectionResult | null }
  | { type: 'METRICS_UPDATE'; metrics: Partial<DetectionMetrics> }
  | { type: 'ERROR'; error: string }
  | { type: 'LOADED_MODEL' }
  | { type: 'CONFIGURED' };
