import "server-only"

import {
  aiChatAction,
  suggestSimilarQuestionsAction,
  suggestGradingAction,
  generateLessonContentAction,
  generateQuestionVariantAction,
  analyzeWeaknessAction,
  generateChildSummaryAction,
  recommendStudyPathAction,
  getAiUsageStatsAction,
  explainErrorAction,
} from "../actions"
import type { AiClientService } from "../types"

/**
 * 创建完整的 AI 客户端服务（含全部 10 个 Action）
 *
 * 用于全局 layout 或需要全部 AI 能力的页面。
 * 通过 React Context 注入，客户端组件通过 useAiClient() 消费。
 */
export function createFullAiClientService(): AiClientService {
  return {
    chat: aiChatAction,
    suggestSimilarQuestions: suggestSimilarQuestionsAction,
    suggestGrading: suggestGradingAction,
    generateLessonContent: generateLessonContentAction,
    generateQuestionVariant: generateQuestionVariantAction,
    analyzeWeakness: analyzeWeaknessAction,
    generateChildSummary: generateChildSummaryAction,
    recommendStudyPath: recommendStudyPathAction,
    getAiUsageStats: getAiUsageStatsAction,
    explainError: explainErrorAction,
  }
}

/**
 * 创建核心 AI 客户端服务（仅 6 个常用 Action）
 *
 * 用于只需要 AI 业务能力（不含家长摘要/学习路径/统计/错题解释）的页面。
 * 可选字段（generateChildSummary/recommendStudyPath/getAiUsageStats/explainError）不注入，
 * 调用方组件需自行处理 undefined 情况。
 */
export function createCoreAiClientService(): AiClientService {
  return {
    chat: aiChatAction,
    suggestSimilarQuestions: suggestSimilarQuestionsAction,
    suggestGrading: suggestGradingAction,
    generateLessonContent: generateLessonContentAction,
    generateQuestionVariant: generateQuestionVariantAction,
    analyzeWeakness: analyzeWeaknessAction,
  }
}
