using Microsoft.AspNetCore.Mvc.RazorPages;
using TaxBaik.Application.Services;
using TaxBaik.Domain.Entities;

namespace TaxBaik.Web.Pages.Blog;

public class BlogPostModel : PageModel
{
    private readonly BlogService _blogService;

    public BlogPost? Post { get; set; }
    public string? HtmlContent { get; set; }

    public BlogPostModel(BlogService blogService)
    {
        _blogService = blogService;
    }

    public async Task OnGetAsync(string slug)
    {
        Post = await _blogService.GetBySlugAsync(slug);
        if (Post != null)
        {
            HtmlContent = Post.Content ?? string.Empty;
            _ = _blogService.IncrementViewCountAsync(Post.Id);
        }
    }
}
