import { Injectable } from '@nestjs/common';
import type { AiProvider, AiGenerateInput, AiGenerateOutput } from './ai-provider.interface';

@Injectable()
export class MockAiProvider implements AiProvider {
  readonly name = 'mock';

  async generate(input: AiGenerateInput): Promise<AiGenerateOutput> {
    const userInput = input.messages.find((m) => m.role === 'user')?.content ?? '';
    const score = Math.min(95, Math.max(30, userInput.length % 60 + 30));

    const result = {
      score,
      masteryLevel: score >= 90 ? 'excellent' : score >= 70 ? 'good' : score >= 50 ? 'partial' : 'weak',
      summary: '用户理解了核心定义，但缺少应用场景。',
      strengths: ['表达清楚', '有一定基础'],
      weaknesses: ['遗漏关键要点', '逻辑层次不足'],
      missingKeyPoints: ['具体应用场景', '与相关概念的关联'],
      misconceptions: [],
      weaknessTypes: ['missing_detail', 'missing_application'],
      focusItems: [
        {
          title: '补充应用场景',
          reason: '回答中缺少实际应用场景的说明',
          suggestion: '建议回顾知识点的应用部分',
          priority: 'high',
        },
      ],
      reviewSuggestion: {
        shouldReview: true,
        intervalDays: 2,
        cardFront: '这个知识点的核心应用场景有哪些？',
        cardBack: '请重新阅读知识点中关于应用的部分。',
      },
    };

    return {
      rawText: JSON.stringify(result),
      usage: {
        model: 'mock',
        inputTokens: 0,
        outputTokens: 0,
      },
      latencyMs: 10,
    };
  }
}
