// Ghost Mechanic - Core Types

export interface DiagnosisRequest {
  artifactId: string;
  errorType: 'runtime' | 'build' | 'behavior' | 'integration' | 'unknown';
  errorMessage?: string;
  userDescription?: string;
  actionLog?: ActionLogEntry[];
  stackTrace?: string;
  browserConsole?: string[];
  componentCode?: string;
  weftConfig?: any;
  originalSpec?: string;
}

export interface ActionLogEntry {
  timestamp: string;
  actionType: string;
  element: {
    type: string;
    id?: string;
    text?: string;
    selector: string;
    value?: any;
  };
  wouldTrigger: {
    endpoint?: string;
    method?: string;
    payload?: any;
    navigation?: string;
  };
}

export interface DiagnosisResult {
  id: string;
  confidence: number; // 0-100
  rootCause: string;
  explanation: string;
  category: 'async' | 'state' | 'props' | 'api' | 'navigation' | 'validation' | 'render' | 'integration' | 'unknown';
  affectedCode: AffectedCode[];
  proposedFix?: ProposedFix;
  needsMoreInfo?: string[];
  alternativeCauses?: AlternativeCause[];
}

export interface AffectedCode {
  file: string;
  lines: [number, number];
  snippet: string;
  highlightLines?: number[];
}

export interface ProposedFix {
  id: string;
  description: string;
  changes: CodeChange[];
  testPlan: string;
  rollbackPlan: string;
  confidence: number;
  risks: string[];
  estimatedEffort: 'trivial' | 'minor' | 'moderate' | 'significant';
}

export interface CodeChange {
  file: string;
  type: 'modify' | 'add' | 'delete';
  lineStart?: number;
  lineEnd?: number;
  before?: string;
  after?: string;
  explanation: string;
}

export interface AlternativeCause {
  description: string;
  confidence: number;
  howToVerify: string;
}

export interface RepairLog {
  id: string;
  timestamp: Date;
  artifactId: string;
  errorType: string;
  diagnosis: DiagnosisResult;
  fixApplied?: ProposedFix;
  outcome: 'success' | 'partial' | 'failed' | 'pending' | 'rejected';
  userFeedback?: string;
  timeToFix?: number; // ms
}

export interface Escalation {
  reason: 'outside_scope' | 'ambiguous_intent' | 'integration_issue' | 'low_confidence' | 'complex_refactor' | 'missing_context';
  explanation: string;
  suggestions: string[];
  supportTicketDraft?: string;
}

export interface PatternMatch {
  patternId: string;
  patternName: string;
  confidence: number;
  matchedSignals: string[];
  suggestedFix: string;
}
