namespace AsadiTools.Models;

public class BlogPost
{
    public int Id { get; set; }
    public string Title { get; set; } = string.Empty;
    public string Slug { get; set; } = string.Empty;
    public string Content { get; set; } = string.Empty;   // raw HTML
    public string? Excerpt { get; set; }
    public string? MetaDescription { get; set; }
    public string? FeaturedImage { get; set; }
    public string? Tags { get; set; }                      // comma-separated
    public bool IsPublished { get; set; } = false;
    public DateTime CreatedAt { get; set; } = DateTime.Now;
    public DateTime UpdatedAt { get; set; } = DateTime.Now;
    public DateTime? PublishedAt { get; set; }

    // Helpers
    public string[] TagList =>
        Tags?.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) ?? [];

    public string EffectiveSlug =>
        !string.IsNullOrWhiteSpace(Slug) ? Slug : $"post-{Id}";

    public string DisplayDate =>
        (PublishedAt ?? CreatedAt) is var dt
            ? AsadiTools.Services.SiteData.ToJalali(dt)
            : string.Empty;
}
