/**
 * Pipeline-specific types for the 6-stage feedback processing pipeline.
 */

import type {
  FeedbackEvent,
  EnrichedFeedbackEvent,
  AnalysisResults,
  ApplyResult,
} from "../types.js";

// ═══════════════════════════════════════════════════════════════
// PIPELINE STAGE RESULTS
// ═══════════════════════════════════════════════════════════════

export interface ValidationResult {
  valid: boolean;
  event?: FeedbackEvent;
  error?: {
    type: "schema" | "orphaned" | "range" | "duplicate";
    message: string;
    details?: unknown;
  };
}

export interface EnrichmentResult {
  success: boolean;
  event?: EnrichedFeedbackEvent;
  error?: string;
}

export interface StorageResult {
  success: boolean;
  filePath?: string;
  error?: string;
}

export interface AnalysisResult {
  success: boolean;
  results?: AnalysisResults;
  eventsAnalyzed?: number;
  error?: string;
}

export interface ActionResult {
  success: boolean;
  result?: ApplyResult;
  error?: string;
}

// ═══════════════════════════════════════════════════════════════
// PIPELINE EXECUTION RESULT
// ═══════════════════════════════════════════════════════════════

export interface PipelineResult {
  success: boolean;
  eventId?: string;
  stages: {
    validate: ValidationResult;
    enrich?: EnrichmentResult;
    store?: StorageResult;
    analyze?: AnalysisResult;
    act?: ActionResult;
  };
  processingTimeMs: number;
  error?: string;
}

// ═══════════════════════════════════════════════════════════════
// PIPELINE CONFIGURATION
// ═══════════════════════════════════════════════════════════════

export interface PipelineConfig {
  /** Path to the data directory for JSONL storage */
  dataDir: string;
  /** Path to the memory files directory */
  memoryDir: string;
  /** Minimum events before triggering analysis */
  analysisThreshold: number;
  /** Whether to run analysis on every event or batch */
  analyzeOnEvery: boolean;
  /** Minimum data points before creating rules */
  minDataPointsForRules: number;
  /** Whether calibration updates are enabled */
  calibrationEnabled: boolean;
  /** Number of days of data to analyze */
  analysisDays: number;
}

export const DEFAULT_PIPELINE_CONFIG: PipelineConfig = {
  dataDir: "data",
  memoryDir: "memory",
  analysisThreshold: 5,
  analyzeOnEvery: false,
  minDataPointsForRules: 5,
  calibrationEnabled: true,
  analysisDays: 30,
};
