using VentaUniformesApplication.Features;
using VentaUniformesApplication.Persistencia.user.commands.CreateUser;
using VentaUniformesApplication.Sesion.Commands.CreateSesion;
using FluentValidation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
//using System.Web.Http;

namespace VentaUniformesapi.Controllers
{
    [Authorize]
    [Route("api/v1/Sesion")]
    [ApiController]
    public class SesionController : ControllerBase
    {
        [AllowAnonymous]
        [HttpPost]
        public async Task<IActionResult> Create(
        [FromBody] InCreateSesionModel model,
            [FromServices] ICreateSesionCommand createSesionCommand,
            [FromServices] IValidator<InCreateSesionModel> validador
            )
        {
            var validacion = await validador.ValidateAsync(model);
            if (!validacion.IsValid)
                return StatusCode(StatusCodes.Status400BadRequest, ResponseApiService.Response(StatusCodes.Status400BadRequest, validacion.Errors));

            var data = await createSesionCommand.Execute(model);


            //var n=int.Parse("h");
            return StatusCode(StatusCodes.Status201Created, ResponseApiService.Response(StatusCodes.Status201Created, data));
        }
    }
}
