import { z } from 'zod';

export const FocusItemSchema = z.object({
  title: z.string().min(1).max(255),
  reason: z.string().min(1).max(1000),
  suggestion: z.string().optional(),
  priority: z.enum(['high', 'normal', 'low']).default('normal'),
});

export const ReviewSuggestionSchema = z.object({
  shouldReview: z.boolean(),
  intervalDays: z.number().int().min(1).max(365),
  cardFront: z.string().optional(),
  cardBack: z.string().optional(),
});

export const ActiveRecallAnalysisResultSchema = z.object({
  score: z.number().int().min(0).max(100),
  masteryLevel: z.enum(['excellent', 'good', 'partial', 'weak', 'none']),
  summary: z.string().min(1).max(2000),
  strengths: z.array(z.string().max(500)).max(10).default([]),
  weaknesses: z.array(z.string().max(500)).max(10).default([]),
  missingKeyPoints: z.array(z.string().max(500)).max(20).default([]),
  misconceptions: z.array(z.string().max(500)).max(10).default([]),
  weaknessTypes: z.array(z.string().max(50)).max(10).default([]),
  focusItems: z.array(FocusItemSchema).max(10).default([]),
  reviewSuggestion: ReviewSuggestionSchema,
});

export type ActiveRecallAnalysisResult = z.infer<typeof ActiveRecallAnalysisResultSchema>;

export const ACTIVE_RECALL_OUTPUT_SCHEMA_DESC = `{
  "score": 72,
  "masteryLevel": "partial",
  "summary": "用户理解了核心定义，但缺少应用场景。",
  "strengths": ["核心概念理解正确", "能用自己的话表达"],
  "weaknesses": ["缺少具体例子", "遗漏了关键应用条件"],
  "missingKeyPoints": ["X的应用条件", "X与Y的关系"],
  "misconceptions": ["将A误解为B"],
  "weaknessTypes": ["missing_detail", "missing_application", "misconception"],
  "focusItems": [
    {
      "title": "X的应用条件",
      "reason": "用户在回答中完全未提及应用条件",
      "suggestion": "建议回顾知识点第三段关于应用条件的内容",
      "priority": "high"
    }
  ],
  "reviewSuggestion": {
    "shouldReview": true,
    "intervalDays": 2,
    "cardFront": "在什么条件下X不能使用？",
    "cardBack": "当Y存在时，X失效。"
  }
}`;
