/**
 * @goosefactory/learning — Main Exports
 *
 * GooseFactory Learning & Feedback Processing System
 *
 * Transforms human feedback from HITL modals into AI learning:
 * - 6-stage feedback processing pipeline
 * - JSONL feedback storage with queries
 * - Pattern analysis and calibration
 * - Memory file integration
 * - Self-improvement loops (pre-check, prediction, diminishing review)
 * - Dashboard KPIs and metrics
 */

// ═══════════════════════════════════════════════════════════════
// TYPES — All feedback data types + Zod schemas
// ═══════════════════════════════════════════════════════════════

export {
  // Zod Schemas (for runtime validation)
  FeedbackEventSchema,
  EnrichedFeedbackEventSchema,
  FeedbackPayloadSchema,
  WorkProductRefSchema,
  DecisionFeedbackSchema,
  DimensionScoreSchema,
  FreeTextFeedbackSchema,
  ComparisonFeedbackSchema,
  AnnotationSchema,
  ConfidenceFeedbackSchema,
  EstimationFeedbackSchema,
  BatchDecisionSchema,
  ModalMetricsSchema,
  EnrichedMetaSchema,
  FeedbackMetaSchema,
  TemperatureFeedbackSchema,
  ChecklistFeedbackSchema,
  RankingFeedbackSchema,
  RetrospectiveFeedbackSchema,

  // Enum schemas
  QualityDimensionEnum,
  PipelineStageEnum,
  WorkProductTypeEnum,
  DecisionValueEnum,
  SeverityEnum,
  AnnotationTypeEnum,
  AnnotationSeverityEnum,
  ConfidenceZoneEnum,
  PreferenceEnum,
  PreferenceStrengthEnum,
  DeviceTypeEnum,
  TimeOfDayEnum,

  // Constants
  TIER_THRESHOLDS,
} from "./types.js";

export type {
  // Core types
  FeedbackEvent,
  EnrichedFeedbackEvent,
  WorkProductRef,
  GenerationContext,
  FeedbackPayload,
  ModalMetrics,
  EnrichedMeta,
  FeedbackMeta,

  // Feedback sub-types
  DecisionFeedback,
  DimensionScore,
  FreeTextFeedback,
  ComparisonFeedback,
  Annotation,
  AnnotationTarget,
  ConfidenceFeedback,
  EstimationFeedback,
  BatchDecision,
  TemperatureFeedback,
  ChecklistFeedback,
  RankingFeedback,
  RetrospectiveFeedback,

  // Enum types
  QualityDimension,
  PipelineStage,
  WorkProductType,
  DecisionValue,
  Severity,
  AnnotationType,
  AnnotationSeverity,
  ConfidenceZone,
  Preference,
  PreferenceStrength,
  DeviceType,
  TimeOfDay,

  // Analysis types
  AnalysisResults,
  ApprovalPatterns,
  DimensionTrend,
  ThemeCluster,
  Anomaly,
  CandidateRule,
  CalibrationCurve,
  CalibrationBucket,
  CalibrationEntry,
  ApplyResult,

  // Self-improvement types
  SelfCheckResult,
  SelfCheckViolation,
  PredictionResponse,
  AutonomyLevel,
  AutonomyTier,
  RegressionStatus,

  // KPI types
  FeedbackStats,
  KPISnapshot,
} from "./types.js";

// ═══════════════════════════════════════════════════════════════
// PIPELINE — 6-stage feedback processing
// ═══════════════════════════════════════════════════════════════

export {
  processFeedback,
  runFullAnalysis,
  getEventsSinceLastAnalysis,
  validateFeedback,
  enrichFeedback,
  analyzeFeedback,
  applyLearnings,
} from "./pipeline/index.js";

export type {
  PipelineResult,
  PipelineConfig,
  ValidationResult,
  EnrichmentResult,
  StorageResult,
  AnalysisResult,
  ActionResult,
} from "./pipeline/types.js";

export { DEFAULT_PIPELINE_CONFIG } from "./pipeline/types.js";

// ═══════════════════════════════════════════════════════════════
// STORAGE — JSONL feedback store + queries
// ═══════════════════════════════════════════════════════════════

export {
  appendFeedback,
  loadFeedbackEvents,
  loadFeedbackForDate,
  countStoredEvents,
  getAvailableDates,
} from "./storage/feedback-store.js";

export {
  queryFeedback,
  getServerTypes,
  getFeedbackForWorkProduct,
} from "./storage/query.js";

export type { FeedbackQuery } from "./storage/query.js";

export {
  computeStats,
  computeStatsFromEvents,
} from "./storage/stats.js";

export type { AggregateStats, WeeklyStats } from "./storage/stats.js";

// ═══════════════════════════════════════════════════════════════
// ANALYSIS — Pattern detection + calibration
// ═══════════════════════════════════════════════════════════════

export { detectPatterns } from "./analysis/patterns.js";
export type { PatternResults } from "./analysis/patterns.js";

export {
  computeCalibration,
  applyCalibration,
  extractCalibrationEntries,
  computePredictionAccuracy,
} from "./analysis/calibration.js";

export {
  buildPreferenceModel,
  analyzeDecisionSpeed,
  identifyConsistentPatterns,
} from "./analysis/preferences.js";

export {
  computeDimensionTrends,
  getDimensionHighlights,
  getDimensionDistributions,
} from "./analysis/dimensions.js";

export { analyzeBehavioral } from "./analysis/behavioral.js";
export type { BehavioralResults } from "./analysis/behavioral.js";

// ═══════════════════════════════════════════════════════════════
// MEMORY — Memory file integration
// ═══════════════════════════════════════════════════════════════

export {
  writeFeedbackPatterns,
  writeQualityStandards,
  writeJakePreferences,
  appendImprovementLog,
} from "./memory/writer.js";

export {
  loadMemoryState,
  readMemoryFile,
  getMemoryFileInfo,
  getMemorySummary,
  getRelevantMemory,
} from "./memory/reader.js";

export type { MemoryState, RelevantMemory } from "./memory/reader.js";

export {
  compressFeedback,
  archiveOldFiles,
} from "./memory/compressor.js";

export type { CompressedLearning } from "./memory/compressor.js";

// ═══════════════════════════════════════════════════════════════
// IMPROVEMENT — Self-improvement loops
// ═══════════════════════════════════════════════════════════════

export { selfCheck } from "./improvement/pre-check.js";
export type { WorkProductForCheck } from "./improvement/pre-check.js";

export {
  predict,
  storePrediction,
  resolvePrediction,
  loadCalibrationHistory,
} from "./improvement/prediction.js";

export {
  decideReview,
  recordReviewOutcome,
  checkRegression,
  getAutonomyLevel,
  getAutonomySummary,
  loadAutonomyLevels,
} from "./improvement/diminishing-review.js";

export type { ReviewDecision } from "./improvement/diminishing-review.js";

export { detectRegression } from "./improvement/regression.js";
export type {
  RegressionReport,
  RegressionDetail,
  RegressionAction,
} from "./improvement/regression.js";

// ═══════════════════════════════════════════════════════════════
// METRICS — Dashboard KPIs
// ═══════════════════════════════════════════════════════════════

export {
  computeKPIs,
  computeFeedbackStats,
  computeWeeklyTrends,
  checkAlerts,
} from "./metrics/kpis.js";

export type { Alert } from "./metrics/kpis.js";
