import { Agent } from './Agent';

export const LEARNING_COURSES = {
  technical_analysis: { cost: 100.0, durationDays: 7, skillImprovement: 0.1, winRateBoost: 0.05 },
  risk_management: { cost: 150.0, durationDays: 10, skillImprovement: 0.15, maxDrawdownReduction: 0.1 },
  market_psychology: { cost: 200.0, durationDays: 14, skillImprovement: 0.2, sentimentAccuracyBoost: 0.1 },
  advanced_strategies: { cost: 500.0, durationDays: 30, skillImprovement: 0.3, newStrategyUnlock: true }
};

export class LearningSystem {
  enrollCourse(agent: Agent, courseName: keyof typeof LEARNING_COURSES, currentTime: number): boolean {
    const course = LEARNING_COURSES[courseName];
    if (agent.economicTracker.balance < course.cost * 1.5) return false;

    agent.economicTracker.balance -= course.cost;
    agent.learningStatus = {
      course: courseName,
      endDate: currentTime + course.durationDays * 24 * 60 * 60 * 1000,
      expectedImprovement: course.skillImprovement
    };
    return true;
  }
  
  updateLearning(agent: Agent, currentTime: number) {
    if (agent.learningStatus && currentTime >= agent.learningStatus.endDate) {
      agent.skillLevel = Math.min(1.0, agent.skillLevel + agent.learningStatus.expectedImprovement);
      const course = LEARNING_COURSES[agent.learningStatus.course as keyof typeof LEARNING_COURSES];
      if ('winRateBoost' in course) {
          agent.winRate = Math.min(1.0, agent.winRate + (course.winRateBoost as number));
      }
      agent.learningStatus = null;
    }
  }
}
