using GermanApp.Domain.Entities; namespace GermanApp.Application.DTOs; /// /// Data Transfer Object for Lesson - used for API responses. /// This is a read-only representation of a Lesson entity. /// public record LessonDto( int Id, string Title, string Description, int Level, string LevelDescription, DateTime CreatedAt, DateTime? UpdatedAt); /// /// Data Transfer Object for creating a new Lesson. /// public record CreateLessonDto( string Title, string Description, int Level); /// /// Data Transfer Object for updating an existing Lesson. /// public record UpdateLessonDto( string Title, string Description, int Level); /// /// Extension methods for mapping between Lesson entity and DTOs. /// public static class LessonDtoExtensions { public static LessonDto ToDto(this Lesson lesson) => new( lesson.Id, lesson.Title, lesson.Description, lesson.Level, GetLevelDescription(lesson.Level), lesson.CreatedAt, lesson.UpdatedAt); private static string GetLevelDescription(int level) => level switch { 1 => "A1 (Beginner)", 2 => "A2 (Elementary)", 3 => "B1 (Intermediate)", 4 => "B2 (Upper Intermediate)", 5 => "C1 (Advanced)", _ => "Unknown" }; public static Lesson ToEntity(this CreateLessonDto dto) => Lesson.Create(dto.Title, dto.Description, dto.Level); }