using DramaLing.Api.Models.Entities;
using DramaLing.Api.Models.DTOs;
namespace DramaLing.Api.Services.Domain.Learning;
///
/// 詞卡服務介面,封裝詞卡相關的業務邏輯
///
public interface IFlashcardService
{
// 基本 CRUD 操作
Task CreateFlashcardAsync(CreateFlashcardRequest request);
Task GetFlashcardAsync(Guid flashcardId, Guid userId);
Task UpdateFlashcardAsync(Guid flashcardId, UpdateFlashcardRequest request);
Task DeleteFlashcardAsync(Guid flashcardId, Guid userId);
// 查詢操作
Task> GetUserFlashcardsAsync(Guid userId, FlashcardQueryOptions? options = null);
Task> GetDueFlashcardsAsync(Guid userId, int limit = 20);
Task> GetFlashcardsByDifficultyAsync(Guid userId, string difficultyLevel);
Task> SearchFlashcardsAsync(Guid userId, string searchTerm);
// 學習相關操作
Task GetStudyRecommendationsAsync(Guid userId);
Task UpdateMasteryLevelAsync(Guid flashcardId, int masteryLevel, Guid userId);
Task MarkAsReviewedAsync(Guid flashcardId, StudyResult result, Guid userId);
// 批次操作
Task> CreateFlashcardsFromAnalysisAsync(SentenceAnalysisData analysis, Guid userId);
Task BulkUpdateMasteryAsync(IEnumerable flashcardIds, int masteryLevel, Guid userId);
// 統計功能
Task GetFlashcardStatsAsync(Guid userId);
Task GetLearningProgressAsync(Guid userId);
}
///
/// 詞卡查詢選項
///
public class FlashcardQueryOptions
{
public int? Limit { get; set; }
public int? Offset { get; set; }
public string? SortBy { get; set; } = "CreatedAt";
public bool SortDescending { get; set; } = true;
public bool? IsFavorite { get; set; }
public bool? IsArchived { get; set; }
public string? DifficultyLevel { get; set; }
public Guid? CardSetId { get; set; }
}
///
/// 學習推薦
///
public class StudyRecommendations
{
public IEnumerable DueCards { get; set; } = new List();
public IEnumerable NewCards { get; set; } = new List();
public IEnumerable ReviewCards { get; set; } = new List();
public IEnumerable ChallengingCards { get; set; } = new List();
public int RecommendedStudyTimeMinutes { get; set; }
public string RecommendationReason { get; set; } = string.Empty;
}
///
/// 學習結果
///
public class StudyResult
{
public int QualityRating { get; set; } // 1-5 SM2 算法評分
public int ResponseTimeMs { get; set; }
public bool IsCorrect { get; set; }
public string? UserAnswer { get; set; }
public DateTime StudiedAt { get; set; } = DateTime.UtcNow;
}
///
/// 詞卡統計
///
public class FlashcardStats
{
public int TotalCards { get; set; }
public int MasteredCards { get; set; }
public int DueCards { get; set; }
public int NewCards { get; set; }
public double MasteryRate => TotalCards > 0 ? (double)MasteredCards / TotalCards : 0;
public Dictionary DifficultyDistribution { get; set; } = new();
public TimeSpan AverageStudyTime { get; set; }
}
///
/// 學習進度
///
public class LearningProgress
{
public int ConsecutiveDays { get; set; }
public int TotalStudyDays { get; set; }
public int WordsLearned { get; set; }
public int WordsMastered { get; set; }
public string CurrentLevel { get; set; } = "A2";
public double ProgressToNextLevel { get; set; }
public DateTime LastStudyDate { get; set; }
public IEnumerable RecentProgress { get; set; } = new List();
}
///
/// 每日進度
///
public class DailyProgress
{
public DateOnly Date { get; set; }
public int CardsStudied { get; set; }
public int CorrectAnswers { get; set; }
public TimeSpan StudyTime { get; set; }
public double AccuracyRate => CardsStudied > 0 ? (double)CorrectAnswers / CardsStudied : 0;
}