namespace DramaLing.Api.Services.Infrastructure; /// /// 統一配置管理服務介面 /// public interface IConfigurationService { /// /// 取得 AI 相關配置 /// Task GetAIConfigurationAsync(); /// /// 取得認證相關配置 /// Task GetAuthConfigurationAsync(); /// /// 取得外部服務配置 /// Task GetExternalServicesConfigurationAsync(); /// /// 取得快取配置 /// Task GetCacheConfigurationAsync(); /// /// 檢查配置是否完整 /// Task ValidateConfigurationAsync(); /// /// 取得環境特定配置 /// T GetEnvironmentConfiguration(string sectionName) where T : class, new(); } /// /// AI 相關配置 /// public class AIConfiguration { public string GeminiApiKey { get; set; } = string.Empty; public string GeminiModel { get; set; } = "gemini-1.5-flash"; public int TimeoutSeconds { get; set; } = 30; public double Temperature { get; set; } = 0.7; public int MaxOutputTokens { get; set; } = 2000; public int MaxRetries { get; set; } = 3; } /// /// 認證相關配置 /// public class AuthConfiguration { public string JwtSecret { get; set; } = string.Empty; public string SupabaseUrl { get; set; } = string.Empty; public string ValidAudience { get; set; } = "authenticated"; public int ClockSkewMinutes { get; set; } = 5; } /// /// 外部服務配置 /// public class ExternalServicesConfiguration { public AzureSpeechConfiguration AzureSpeech { get; set; } = new(); public DatabaseConfiguration Database { get; set; } = new(); } /// /// Azure Speech 配置 /// public class AzureSpeechConfiguration { public string SubscriptionKey { get; set; } = string.Empty; public string Region { get; set; } = string.Empty; public bool IsConfigured => !string.IsNullOrEmpty(SubscriptionKey) && !string.IsNullOrEmpty(Region); } /// /// 資料庫配置 /// public class DatabaseConfiguration { public string ConnectionString { get; set; } = string.Empty; public bool UseInMemoryDb { get; set; } = false; public int CommandTimeoutSeconds { get; set; } = 30; } /// /// 快取配置 /// public class CacheConfiguration { public bool EnableDistributedCache { get; set; } = false; public TimeSpan DefaultExpiry { get; set; } = TimeSpan.FromMinutes(10); public TimeSpan AnalysisCacheExpiry { get; set; } = TimeSpan.FromHours(2); public TimeSpan UserCacheExpiry { get; set; } = TimeSpan.FromMinutes(30); public int MaxMemoryCacheSizeMB { get; set; } = 100; } /// /// 配置驗證結果 /// public class ConfigurationValidationResult { public bool IsValid { get; set; } public List Errors { get; set; } = new(); public List Warnings { get; set; } = new(); public Dictionary ConfigurationSummary { get; set; } = new(); }