/**
 * ============================================
 * EXERCISE TYPES
 * ============================================
 * 
 * Types for exercises, attempts, and solutions
 * shared between frontend and backend
 */

// ============================================
// ENUMS
// ============================================

export type ExerciseType = 
  | 'MULTIPLE_CHOICE' 
  | 'OPEN_ENDED' 
  | 'TRUE_FALSE' 
  | 'CALCULATION';

export type ExerciseDifficulty = 'EASY' | 'MEDIUM' | 'HARD';

export type ExerciseStatus = 'CORRECT' | 'INCORRECT' | 'PARTIAL' | 'SKIPPED';

export type TopicType = 
  | 'VECTORES'
  | 'MATRICES'
  | 'SISTEMAS'
  | 'ESPACIOS_VECTORIALES'
  | 'PROGRAMACION_LINEAL';

export type ModuleType = 'FUNDAMENTOS' | 'SISTEMAS' | 'APLICACIONES';

// ============================================
// CORE EXERCISE TYPES
// ============================================

export interface Exercise {
  id: string;
  moduleId: string;
  topicId?: string;
  type: ExerciseType;
  difficulty: ExerciseDifficulty;
  statement: string;
  correctAnswer: string;
  solutionSteps: SolutionStep[];
  formulas?: string[];
  hints?: string[];
  options?: ExerciseOption[];
  points: number;
  isAIGenerated?: boolean;
}

export interface ExerciseOption {
  id: string;
  text: string;
  isCorrect: boolean;
}

export interface SolutionStep {
  step: number;
  description: string;
  formula?: string;
}

// ============================================
// ATTEMPT SUBMISSION
// ============================================

export interface SubmitAttemptRequest {
  answer: string;
  timeSpent: number;
  hintsUsed?: number;
  skipped?: boolean;
}

export interface SubmitAttemptResponse {
  isCorrect: boolean;
  points: number;
  message: string;
  correctAnswer?: string;
  solutionSteps?: SolutionStep[];
  newAchievements?: AchievementUnlock[];
}

export interface AchievementUnlock {
  code: string;
  name: string;
  description: string;
  icon: string;
}

// ============================================
// EXERCISE ATTEMPT (History)
// ============================================

export interface ExerciseAttempt {
  id: string;
  userId: string;
  exerciseId: string;
  userAnswer: string;
  status: ExerciseStatus;
  pointsEarned: number;
  timeSpentSeconds: number;
  attemptedAt: string;
  hintsUsed?: number;
}

// ============================================
// EXERCISE CONTENT (Detailed)
// ============================================

export interface ExerciseContent {
  statement: string;
  correctAnswer: string;
  solutionSteps?: SolutionStep[];
  formulas?: LatexFormula[];
  hints?: ExerciseHint[];
  multipleChoiceOptions?: MultipleChoiceOption[];
  calculationSteps?: CalculationStep[];
}

export interface LatexFormula {
  name: string;
  latex: string;
  description: string;
  category?: string;
}

export interface ExerciseHint {
  hint: string;
  cost: number;
}

export interface MultipleChoiceOption {
  option: string;
  isCorrect: boolean;
  explanation?: string;
}

export interface CalculationStep {
  step: number;
  operation: string;
  result: string;
  latexFormula?: string;
}
