import Combine
import Foundation

@MainActor
class AIAnalysisViewModel: ObservableObject {
    @Published var analysisResult: AIAnalysisResult?
    @Published var isAnalyzing = false
    @Published var errorMessage: String?

    func requestAnalysis(questionText: String, knowledgeItemContent: String, userAnswer: String) async {
        isAnalyzing = true
        errorMessage = nil
        do {
            analysisResult = try await AIAnalysisService.shared.analyze(
                questionText: questionText,
                knowledgeItemContent: knowledgeItemContent,
                userAnswer: userAnswer
            )
        } catch {
            errorMessage = "AI 分析失败"
        }
        isAnalyzing = false
    }
}
