using Diligent.WebAPI.Host.DTOs.Customer;
using Diligent.WebAPI.Host.Mediator.Authentication.Commands;
using Diligent.WebAPI.Host.Mediator.Authentication.Queries;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace Diligent.WebAPI.Host.Controllers
{
    [ApiVersion("1.0")]
    [ApiController]
    [Route("v{version:apiVersion}/[controller]")]
    public class AuthenticationController : ControllerBase
    {
        // password for every user in database is "Nekasifra123!"
        private readonly IMediator _mediator;
        public AuthenticationController(IMediator mediator)
        {
            _mediator = mediator;
        }
        [HttpPost("login")]
        public async Task<ActionResult<CustomerReadDTO>> Login(CustomerLoginDTO customerLoginDTO) =>
             await _mediator.Send(new LoginUserQuery(customerLoginDTO));

        [HttpPost("addRole")]
        public async Task<ActionResult> CreateRole(string nameOfRole)
        {
            await _mediator.Send(new AddRoleCommand(nameOfRole));

            return StatusCode(201);
        }

        [HttpPost("register")]
        public async Task<ActionResult<CustomerReadDTO>> Register(CustomerCreateDTO customerCreateDTO) =>
            await _mediator.Send(new RegisterUserCommand(customerCreateDTO));
    }
}
