using System.Text.Json.Serialization; namespace ChaoXingAutoClass.Core.Models; public sealed class AppSettings { public string HomeUrl { get; set; } = "https://i.chaoxing.com/base?ws=1"; public string ApiBaseUrl { get; set; } = "https://api.deepseek.com"; public string Model { get; set; } = "deepseek-flash"; [JsonIgnore] public string ApiKey { get; set; } = ""; public string EncryptedApiKey { get; set; } = ""; public bool VisionEnabled { get; set; } = true; public bool Muted { get; set; } = true; public bool AutoAnswer { get; set; } = true; public bool AutoSubmit { get; set; } = true; public bool RequireCourseEvidence { get; set; } public double MinimumConfidence { get; set; } = .80; public bool StopOnUncertainAnswers { get; set; } public int FrameIntervalSeconds { get; set; } = 20; public int FramesPerAnalysis { get; set; } = 6; public int StallTimeoutSeconds { get; set; } = 120; public string CourseNotes { get; set; } = ""; public string TranscriptPath { get; set; } = ""; public bool TranscriptionEnabled { get; set; } = true; public string TranscriptionEngine { get; set; } = "auto"; public string WhisperModel { get; set; } = "base"; public string WhisperLanguage { get; set; } = "zh"; public string WhisperModelPath { get; set; } = ""; public bool AutomaticReferences { get; set; } = true; public bool ReviewMultipleChoice { get; set; } = true; public bool DeepReviewEnabled { get; set; } public bool AutoHomework { get; set; } = true; public int MaximumConcurrentCourses { get; set; } = 3; public void Validate() { if (MaximumConcurrentCourses is < 1 or > 8) throw new ArgumentException("同时学习课程数必须在 1 到 8 之间。"); if (!Uri.TryCreate(ApiBaseUrl.TrimEnd('/') + "/", UriKind.Absolute, out var uri) || (uri.Scheme != "https" && !(uri.Scheme == "http" && uri.IsLoopback)) || !string.IsNullOrEmpty(uri.UserInfo) || !string.IsNullOrEmpty(uri.Query) || !string.IsNullOrEmpty(uri.Fragment)) throw new ArgumentException("API 地址必须为 HTTPS;本地测试服务可使用回环 HTTP 地址,地址不能含凭据或查询参数。"); if (string.IsNullOrWhiteSpace(Model)) throw new ArgumentException("请设置 DeepSeek 模型名称。"); if (!double.IsFinite(MinimumConfidence) || MinimumConfidence is < 0 or > 1) throw new ArgumentException("最低置信度必须在 0 到 1 之间。"); if (FrameIntervalSeconds is < 5 or > 600) throw new ArgumentException("画面采集间隔应为 5–600 秒。"); if (FramesPerAnalysis is < 1 or > 12) throw new ArgumentException("每批画面数量应为 1–12。"); if (StallTimeoutSeconds is < 30 or > 1800) throw new ArgumentException("停滞超时应为 30–1800 秒。"); if (WhisperModel is not ("base" or "small")) throw new ArgumentException("Whisper 模型应为 base 或 small。"); if (TranscriptionEngine is not ("auto" or "windows" or "whisper")) throw new ArgumentException("转写引擎应为 auto、windows 或 whisper。"); if (string.IsNullOrWhiteSpace(WhisperLanguage)) throw new ArgumentException("请设置转写语言,如 zh、en 或 auto。"); } }