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

namespace TaxBaik.Web.Pages.Admin.Announcements;

[Authorize(AuthenticationSchemes = AdminAuthDefaults.Scheme)]
public class CreateModel(AnnouncementService announcementService) : PageModel
{
    [BindProperty]
    public AnnouncementDto Input { get; set; } = new();

    public IActionResult OnGet() => Page();

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

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