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.Clients;

[Authorize(AuthenticationSchemes = AdminAuthDefaults.Scheme)]
public class CreateModel(ClientService clientService) : PageModel
{
    [BindProperty]
    public CreateClientDto Input { get; set; } = new();

    public IActionResult OnGet() => Page();

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

        var id = await clientService.CreateAsync(Input, ct);
        return RedirectToPage("/Admin/Clients/Detail", new { id });
    }
}
