namespace GermanApp.Domain.Entities; /// /// Represents a user's progress through lessons. /// Tracks completion status and quiz scores. /// public class UserProgress { public int Id { get; private set; } public int UserId { get; private set; } public int LessonId { get; private set; } public bool IsCompleted { get; private set; } public int QuizScore { get; private set; } public DateTime LastAttemptDate { get; private set; } // Navigation properties public virtual User? User { get; private set; } public virtual Lesson? Lesson { get; private set; } /// /// Constructor for EF Core deserialization. /// private UserProgress() { } /// /// Factory method to create a new user progress record. /// /// ID of the user /// ID of the lesson public static UserProgress Create(int userId, int lessonId) { return new UserProgress { UserId = userId, LessonId = lessonId, IsCompleted = false, QuizScore = 0, LastAttemptDate = DateTime.UtcNow }; } /// /// Marks the lesson as completed. /// /// The score achieved on the quiz (0-100) public void MarkAsCompleted(int quizScore) { if (quizScore < 0 || quizScore > 100) throw new ArgumentOutOfRangeException(nameof(quizScore), "Score must be between 0 and 100"); IsCompleted = true; QuizScore = quizScore; LastAttemptDate = DateTime.UtcNow; } /// /// Updates the quiz score without marking as completed. /// public void UpdateQuizScore(int quizScore) { if (quizScore < 0 || quizScore > 100) throw new ArgumentOutOfRangeException(nameof(quizScore), "Score must be between 0 and 100"); QuizScore = quizScore; LastAttemptDate = DateTime.UtcNow; } /// /// Resets the progress (e.g., when user wants to redo a lesson). /// public void Reset() { IsCompleted = false; QuizScore = 0; LastAttemptDate = DateTime.UtcNow; } /// /// Checks if the user passed the lesson (80% or higher). /// public bool HasPassed() => QuizScore >= 80; }