using Application.Aggregates.Users;
using Application.Aggregates.Users.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Server.Infrastructure;

namespace Server.Pages.Panel.Users;

public class CreateModel
    (UsersApplication usersApplication) : BasePageModel
{
    [BindProperty]
    public CreateUserViewModel CreateViewModel { get; set; } = new();

    public void OnGet()
    {
    }

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

        await usersApplication.CreateAsync(CreateViewModel);

        return RedirectToPage("Index");
    }
}
