export type InterventionRecord = {
  id: string;
  description: string;
  outcome: 'successful' | 'unsuccessful';
  details?: string;
  date: string;
  relatedEventId?: string;
};

export type CandidateLearning = {
  id: string;
  observation: string;
  action: string;
  outcome: string;
  learning: string;
  confidence: 'low' | 'medium' | 'high';
  evidenceCount: number;
  firstNoted: string;
  lastConfirmed?: string;
};

export type AnalysisStatus = 'pending' | 'analyzing' | 'complete' | 'failed';

export type PhotoIntelligenceType = 'environment' | 'placement' | 'setup' | 'progress';

export type PhotoIntelligenceResult = {
  photoUri: string;
  photoType: PhotoIntelligenceType;
  summary: string;
  extractedAt: string;
  analysisStatus: AnalysisStatus;
  lastAnalysisAttemptAt?: string;
  analysisErrorMessage?: string;
  retryCount: number;
};

export type PlantIntelligenceProfile = {
  plantId: string;
  identitySummary: string;
  environmentSummary: string;
  placementSummary: string;
  setupSummary: string;
  historySummary: string;
  activeIssuesSummary: string;
  successfulInterventions: InterventionRecord[];
  unsuccessfulInterventions: InterventionRecord[];
  growthPatternSummary: string;
  recentTrendSummary: string;
  candidateLearnings: CandidateLearning[];
  photoIntelligenceHistory: PhotoIntelligenceResult[];
  createdAt: string;
  updatedAt: string;
};

export type InvestigationContextPacket = {
  identitySummary: string;
  environmentSummary: string;
  placementSummary: string;
  setupSummary: string;
  historySummary: string;
  activeIssuesSummary: string;
  successfulInterventions: InterventionRecord[];
  unsuccessfulInterventions: InterventionRecord[];
  growthPatternSummary: string;
  recentTrendSummary: string;
  candidateLearnings: CandidateLearning[];
};

export type PhotoAnalysisInput = {
  photoUri: string;
  photoType: PhotoIntelligenceType;
  plantId: string;
  plantCommonName?: string;
  plantScientificName?: string;
  forceReanalyze?: boolean;
  /** Optional pre-built plant memory block (from buildPlantMemoryContext) to give the AI history. */
  plantMemory?: string;
  /** Compass heading in degrees. Collected for environment/placement/setup photos when available. */
  heading?: number;
  /** Altitude in meters above sea level. Collected for environment/placement/setup photos when available. */
  altitude?: number;
};

export type RecoveredPhotoAnalysis = {
  plantId: string;
  photoUri: string;
  photoType: PhotoIntelligenceType;
};
