using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; namespace QuestionsApi.Models; public sealed class UserNotepad { [BsonId, BsonRepresentation(BsonType.ObjectId)] public string? Id { get; set; } public string UserId { get; set; } = ""; public string Content { get; set; } = ""; public long Revision { get; set; } public DateTime CreatedUtc { get; set; } = DateTime.UtcNow; public DateTime UpdatedUtc { get; set; } = DateTime.UtcNow; } public sealed class UpdateUserNotepadRequest { public string Content { get; set; } = ""; public long ExpectedRevision { get; set; } } public sealed class UserNotepadResponse { public string Content { get; set; } = ""; public long Revision { get; set; } public DateTime? UpdatedUtc { get; set; } public static UserNotepadResponse Empty() => new(); public static UserNotepadResponse FromModel(UserNotepad note) => new() { Content = note.Content, Revision = note.Revision, UpdatedUtc = note.UpdatedUtc }; } public static class UserNotepadValidator { public const int MaxContentLength = 50_000; public static string? Validate(UpdateUserNotepadRequest request) { if (request.ExpectedRevision < 0) return "expectedRevision cannot be negative"; if ((request.Content ?? "").Length > MaxContentLength) return $"content must be {MaxContentLength} characters or fewer"; return null; } }