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

namespace TaxBaik.Web.Pages.Admin.Faqs;

[Authorize(AuthenticationSchemes = AdminAuthDefaults.Scheme)]
public class CreateModel(FaqService faqService) : PageModel
{
    [BindProperty]
    public Faq Input { get; set; } = new();

    public IReadOnlyList<string> Categories => FaqService.Categories;

    public IActionResult OnGet()
    {
        Input.IsActive = true;
        return Page();
    }

    public async Task<IActionResult> OnPostAsync(CancellationToken ct)
    {
        if (!ModelState.IsValid)
            return Page();

        await faqService.CreateAsync(Input, ct);
        return RedirectToPage("/Admin/Faqs/Index");
    }
}
