using System.ComponentModel.DataAnnotations; using Microsoft.EntityFrameworkCore; namespace DramaLing.Api.Models.Entities; /// /// 選項詞彙庫實體 - 用於生成測驗選項的詞彙資料庫 /// [Index(nameof(Word), IsUnique = true, Name = "IX_OptionsVocabulary_Word")] [Index(nameof(CEFRLevel), Name = "IX_OptionsVocabulary_CEFR")] [Index(nameof(PartOfSpeech), Name = "IX_OptionsVocabulary_PartOfSpeech")] [Index(nameof(WordLength), Name = "IX_OptionsVocabulary_WordLength")] [Index(nameof(IsActive), Name = "IX_OptionsVocabulary_Active")] [Index(nameof(CEFRLevel), nameof(PartOfSpeech), nameof(WordLength), Name = "IX_OptionsVocabulary_Core_Matching")] public class OptionsVocabulary { /// /// 主鍵 /// public Guid Id { get; set; } /// /// 詞彙內容 /// [Required] [MaxLength(100)] public string Word { get; set; } = string.Empty; /// /// CEFR 難度等級 (A1, A2, B1, B2, C1, C2) /// [Required] [MaxLength(2)] [RegularExpression("^(A1|A2|B1|B2|C1|C2)$", ErrorMessage = "CEFR等級必須為A1, A2, B1, B2, C1, C2之一")] public string CEFRLevel { get; set; } = string.Empty; /// /// 詞性 (noun, verb, adjective, adverb, pronoun, preposition, conjunction, interjection, idiom) /// [Required] [MaxLength(20)] [RegularExpression("^(noun|verb|adjective|adverb|pronoun|preposition|conjunction|interjection|idiom)$", ErrorMessage = "詞性必須為有效值")] public string PartOfSpeech { get; set; } = string.Empty; /// /// 字數(字元長度)- 自動從 Word 計算 /// public int WordLength { get; set; } /// /// 是否啟用 /// public bool IsActive { get; set; } = true; /// /// 創建時間 /// public DateTime CreatedAt { get; set; } = DateTime.UtcNow; /// /// 更新時間 /// public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; /// /// 自動計算字數 /// public void CalculateWordLength() { WordLength = Word?.Length ?? 0; } /// /// 更新時間戳 /// public void UpdateTimestamp() { UpdatedAt = DateTime.UtcNow; } }