using System.Text.Json.Serialization; namespace CORP_MAUI.Models; /// /// Модель поста/новости /// public class Post { public int Id { get; set; } [JsonPropertyName("title")] public string Title { get; set; } = string.Empty; [JsonPropertyName("text")] public string? Text { get; set; } private string _content = string.Empty; [JsonPropertyName("body")] public string Content { get => !string.IsNullOrWhiteSpace(_content) ? _content : (Text ?? string.Empty); set => _content = value; } [JsonPropertyName("image_url")] public string? ImageUrl { get; set; } [JsonPropertyName("image")] public string? Image { get; set; } [JsonIgnore] public string? DisplayImageUrl { get { string? url = !string.IsNullOrEmpty(ImageUrl) ? ImageUrl : Image; if (string.IsNullOrEmpty(url)) return null; // Handle protocol-relative URLs (e.g. //cdn.com/img.jpg) if (url.StartsWith("//")) { return $"https:{url}"; } // Если ссылка уже абсолютная - возвращаем как есть if (url.StartsWith("http", StringComparison.OrdinalIgnoreCase)) return url; // Если ссылка относительная - добавляем домен string cleanUrl = url.TrimStart('/'); return $"https://corp.robotail.pro/{cleanUrl}"; } } [JsonPropertyName("date")] public DateTime? Date { get; set; } [JsonIgnore] public DateTime DisplayDate => (CreatedAt.Year > 2000 ? CreatedAt : (Date ?? DateTime.Now)).ToLocalTime(); public User? Author { get; set; } [JsonPropertyName("created_at")] public DateTime CreatedAt { get; set; } [JsonPropertyName("updated_at")] public DateTime UpdatedAt { get; set; } [JsonPropertyName("likes_count")] public int LikesCount { get; set; } [JsonPropertyName("comments_count")] public int CommentsCount { get; set; } public List Tags { get; set; } = new(); }