using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SCM.Application.Authentication;
using SCM.Application.Authentication.Dtos;
using SCM.Shared.Api;
namespace SCM.Api.Controllers;
/// Autenticação e emissão de tokens JWT.
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/auth")]
[Produces("application/json")]
public sealed class AuthController : ControllerBase
{
private readonly IAuthService _authService;
public AuthController(IAuthService authService) => _authService = authService;
/// Autentica um usuário e retorna um token de acesso.
[HttpPost("login")]
[AllowAnonymous]
[ProducesResponseType(typeof(LoginResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status401Unauthorized)]
public async Task> Login(
[FromBody] LoginRequest request, CancellationToken ct = default)
=> Ok(await _authService.LoginAsync(request, ct));
}