using Asp.Versioning; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SCM.Application.Planejamento; using SCM.Application.Planejamento.Dtos; using SCM.Shared.Api; using SCM.Shared.Constants; namespace SCM.Api.Controllers; /// Módulo MPL — funcionários (pessoal de obra). [ApiController] [ApiVersion("1.0")] [Route("api/v{version:apiVersion}/funcionarios")] [Authorize] [Produces("application/json")] public sealed class FuncionariosController : ControllerBase { private readonly IFuncionarioService _service; public FuncionariosController(IFuncionarioService service) => _service = service; /// Lista todos os funcionários (ordenados por nome). [HttpGet] [ProducesResponseType(typeof(IReadOnlyList), StatusCodes.Status200OK)] public async Task>> GetAll(CancellationToken ct = default) => Ok(await _service.GetAllAsync(ct)); /// Obtém um funcionário pelo identificador. [HttpGet("{id:guid}")] [ProducesResponseType(typeof(FuncionarioResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task> GetById(Guid id, CancellationToken ct = default) => Ok(await _service.GetByIdAsync(id, ct)); /// Cria um funcionário. [HttpPost] [Authorize(Roles = Roles.Administrador + "," + Roles.Gestor)] [ProducesResponseType(typeof(FuncionarioResponse), StatusCodes.Status201Created)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status409Conflict)] public async Task> Create( [FromBody] CreateFuncionarioRequest request, CancellationToken ct = default) { var created = await _service.CreateAsync(request, ct); return CreatedAtAction(nameof(GetById), new { id = created.Id, version = "1.0" }, created); } /// Altera um funcionário (matrícula é imutável). [HttpPut("{id:guid}")] [Authorize(Roles = Roles.Administrador + "," + Roles.Gestor)] [ProducesResponseType(typeof(FuncionarioResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task> Update( Guid id, [FromBody] UpdateFuncionarioRequest request, CancellationToken ct = default) => Ok(await _service.UpdateAsync(id, request, ct)); /// Exclui um funcionário (bloqueado se estiver alocado em equipe). [HttpDelete("{id:guid}")] [Authorize(Roles = Roles.Administrador)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status409Conflict)] public async Task Delete(Guid id, CancellationToken ct = default) { await _service.DeleteAsync(id, ct); return NoContent(); } }