using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace GermanApp.Domain.Entities;
///
/// Represents a segment of a continuous story for a specific level and lesson.
/// Story segments are unlocked sequentially as users complete lessons.
///
public class StorySegment
{
public int Id { get; private set; }
///
/// The CEFR level this story segment belongs to.
///
public int LevelId { get; private set; }
///
/// The lesson this story segment is associated with.
/// Can be null if the segment is an introduction or conclusion.
///
public int? LessonId { get; private set; }
///
/// The text content of the story segment.
///
public string Content { get; private set; } = string.Empty;
///
/// URL path to the audio file for this story segment.
///
public string? AudioUrl { get; private set; }
///
/// The order of this segment within the level's story.
/// Segments are displayed in ascending order.
///
public int Order { get; private set; }
///
/// Title or brief description of this story segment.
///
public string Title { get; private set; } = string.Empty;
///
/// Theme or topic of this story segment.
///
public string Theme { get; private set; } = string.Empty;
///
/// Estimated reading time in minutes.
///
public int EstimatedReadingMinutes { get; private set; }
///
/// Whether this segment is active and visible to users.
///
public bool IsActive { get; private set; } = true;
///
/// Timestamp when the segment was created.
///
public DateTime CreatedAt { get; private set; }
///
/// Timestamp when the segment was last updated.
///
public DateTime? UpdatedAt { get; private set; }
// Navigation properties (EF Core will handle these)
public virtual Level? Level { get; private set; }
public virtual Lesson? Lesson { get; private set; }
///
/// Constructor for EF Core deserialization.
///
private StorySegment() { }
///
/// Factory method to create a new story segment.
///
/// ID of the level this segment belongs to
/// Optional ID of the associated lesson
/// The story text content
/// The order within the level's story
/// Title of the segment
/// Theme or topic of the segment
/// Estimated reading time in minutes
/// New StorySegment instance
public static StorySegment Create(
int levelId,
int? lessonId,
string content,
int order,
string title,
string theme,
int estimatedReadingMinutes = 2)
{
return new StorySegment
{
LevelId = levelId,
LessonId = lessonId,
Content = content,
Order = order,
Title = title,
Theme = theme,
EstimatedReadingMinutes = estimatedReadingMinutes,
CreatedAt = DateTime.UtcNow
};
}
///
/// Updates the content of the story segment.
///
/// New content text
public void UpdateContent(string newContent)
{
Content = newContent;
UpdatedAt = DateTime.UtcNow;
}
///
/// Updates the audio URL for this segment.
///
/// URL path to the audio file
public void UpdateAudioUrl(string audioUrl)
{
AudioUrl = audioUrl;
UpdatedAt = DateTime.UtcNow;
}
///
/// Updates the title of the story segment.
///
/// New title
public void UpdateTitle(string newTitle)
{
Title = newTitle;
UpdatedAt = DateTime.UtcNow;
}
///
/// Updates the theme of the story segment.
///
/// New theme
public void UpdateTheme(string newTheme)
{
Theme = newTheme;
UpdatedAt = DateTime.UtcNow;
}
///
/// Updates the estimated reading time.
///
/// Estimated reading time in minutes
public void UpdateEstimatedReadingMinutes(int minutes)
{
EstimatedReadingMinutes = minutes;
UpdatedAt = DateTime.UtcNow;
}
///
/// Updates the order of this segment within the level's story.
///
/// New order value
public void UpdateOrder(int newOrder)
{
Order = newOrder;
UpdatedAt = DateTime.UtcNow;
}
///
/// Updates the associated lesson.
///
/// New lesson ID (can be null)
public void UpdateLesson(int? newLessonId)
{
LessonId = newLessonId;
UpdatedAt = DateTime.UtcNow;
}
///
/// Activates this story segment.
///
public void Activate()
{
IsActive = true;
UpdatedAt = DateTime.UtcNow;
}
///
/// Deactivates this story segment.
///
public void Deactivate()
{
IsActive = false;
UpdatedAt = DateTime.UtcNow;
}
}