// ── Batch Audit Manifest types ────────────────────────────────────────────────

export interface AuditDetection {
  bunch_id: number;
  ripeness_class: string;
  confidence_pct: number;
  is_health_alert: boolean;
  bounding_box: { x1: number; y1: number; x2: number; y2: number };
  norm_box: { x1: number; y1: number; x2: number; y2: number } | null;
}

export interface BatchResult {
  image_id: string;
  timestamp: string;           // ISO 8601
  status: 'ok' | 'error';
  detections: AuditDetection[];
  performance: {
    inference_ms: number;
    processing_ms: number;
    round_trip_ms: number;     // wall-clock from sendBase64 to pong
  };
  technical_evidence: {
    engine: 'NestJS-ONNX';
    archive_id: string;
    total_count: number;
    threshold: number;
    industrial_summary: Record<string, number>;
    raw_tensor_sample: number[][];
  };
  localBlobUrl?: string;       // temporary object URL for evidence canvas; revoke after use
  error?: string;
}

export interface FullSessionReport {
  session_id: string;
  generated_at: string;        // ISO 8601
  meta: {
    total_images: number;
    successful: number;
    failed: number;
    total_time_ms: number;
    avg_inference_ms: number;
    avg_round_trip_ms: number;
  };
  results: BatchResult[];
}

// ── Existing interfaces ───────────────────────────────────────────────────────

export interface BoundingBox {
  x1: number;
  y1: number;
  x2: number;
  y2: number;
}

export interface DetectionResult {
  bunch_id: number;
  class: string;
  confidence: number;
  is_health_alert: boolean;
  box: [number, number, number, number]; // [x1, y1, x2, y2]
  norm_box?: [number, number, number, number]; // Normalized
}

export interface IndustrialSummary {
  [className: string]: number;
}

export interface AnalysisResponse {
  status: string;
  current_threshold: number;
  total_count: number;
  industrial_summary: IndustrialSummary;
  detections: DetectionResult[];
  inference_ms: number;
  processing_ms: number;
  archive_id: string;
  raw_tensor_sample?: number[][];
  technical_evidence?: {
    engine: 'NestJS-ONNX';
    archive_id: string;
    total_count: number;
    threshold: number;
    industrial_summary: IndustrialSummary;
    raw_tensor_sample: number[][];
  };
}
