/**
 * TypeScript interfaces for prompt version control system
 */

export interface PromptMetadata {
  version: string;
  lastUpdated: string;
  author: string;
  description: string;
  changeHistory: ChangeHistoryEntry[];
}

export interface ChangeHistoryEntry {
  version: string;
  date: string;
  author: string;
  changes: string[];
}

export interface PromptTemplate {
  metadata: PromptMetadata;
  template: string;
  parameters: PromptParameter[];
  examples?: PromptExample[];
}

export interface PromptParameter {
  name: string;
  type: 'string' | 'number' | 'boolean' | 'object' | 'array';
  required: boolean;
  description: string;
  defaultValue?: any;
}

export interface PromptExample {
  title: string;
  description: string;
  input: Record<string, any>;
  expectedOutput?: string;
}

// Workflow Agent specific interfaces
export interface WorkflowDetectionInput {
  aggregatedData: string;
  sessionMetadata: SessionMetadata[];
}

export interface SessionMetadata {
  sessionId: string;
  projectId: string;
  projectName: string;
  createdAt: string;
  duration: number;
  url: string;
  analysisLength: number;
  lineByLineAnalysis: string;
}

export interface WorkflowOutput {
  name: string;
  description: string;
  goal: string;
  steps: WorkflowStep[];
  sessionIds: string[];
  startTimestamps: string[];
  endTimestamps: string[];
}

export interface WorkflowStep {
  order: number;
  description: string;
  occurrences: StepOccurrence[];
}

export interface StepOccurrence {
  sessionId: string;
  timestamp: string;
}

export interface WorkflowDetectionOutput {
  workflows: WorkflowOutput[];
  reasoning: string;
}

export interface WorkflowReviewOutput extends WorkflowDetectionOutput {
  reviewNotes?: string;
}

export interface WorkflowDeleteOutput extends WorkflowDetectionOutput {
  deletedWorkflows: string[];
  deletionNotes?: string;
}

export interface JudgeEvaluation {
  selectedOption: string;
  reasoning: string;
  evaluationSteps: string[];
  granularityScore?: number;
  hallucinationScore?: number;
  coherenceScore?: number;
  crossSessionPatternScore?: number;
  timestampAccuracyScore?: number;
  aggregateQualityScore?: number;
  filteringQualityScore?: number;
  overallScore?: number;
}

// Deduplication Agent interfaces
export interface DeduplicationInput {
  newWorkflow: WorkflowOutput;
  existingWorkflows: WorkflowOutput[];
  projectId: string;
}

export interface DeduplicationResponse {
  action: 'new' | 'duplicate' | 'consolidation' | 'generalization';
  targetWorkflowId?: string;
  consolidatedWorkflow?: WorkflowOutput;
  reasoning: string;
  similarity_score?: number;
}

export interface PromptLibrary {
  workflowAgent: {
    detection: PromptTemplate;
    review: PromptTemplate;
    judge: PromptTemplate;
  };
  deduplicationAgent: {
    analyze: PromptTemplate;
  };
  common: {
    baseInstructions: PromptTemplate;
    outputFormatting: PromptTemplate;
  };
}