using System.Text.Json; using Femto.Common.Domain; using Femto.Modules.Blog.Domain.Posts.Events; using Femto.Modules.Blog.Emoji; namespace Femto.Modules.Blog.Domain.Posts; internal class Post : Entity { public Guid Id { get; private set; } public Guid AuthorId { get; private set; } public string Content { get; private set; } = null!; public IList Media { get; private set; } public IList Reactions { get; private set; } = []; public bool IsPublic { get; set; } public DateTimeOffset PostedOn { get; private set; } private string PossibleReactionsJson { get; set; } = null!; public IEnumerable PossibleReactions { get => JsonSerializer.Deserialize>(this.PossibleReactionsJson)!; init => PossibleReactionsJson = JsonSerializer.Serialize(value); } private Post() { } public Post(Guid authorId, string content, IList media) { this.Id = Guid.CreateVersion7(); this.AuthorId = authorId; this.Content = content; this.Media = media; this.PossibleReactions = AllEmoji.GetRandomEmoji(5); this.PostedOn = DateTimeOffset.UtcNow; this.AddDomainEvent(new PostCreated(this)); } }