using Asp.Versioning; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using SCM.Application.Controle; using SCM.Application.Medicao; using SCM.Application.Qualidade; using SCM.Application.Relatorios; using SCM.Shared.Api; namespace SCM.Api.Controllers; /// Geração de PDFs dos relatórios (faturamento, acompanhamento, relatório técnico). [ApiController] [ApiVersion("1.0")] [Route("api/v{version:apiVersion}")] [Authorize] public sealed class RelatoriosPdfController : ControllerBase { private readonly IPdfReportService _pdf; public RelatoriosPdfController(IPdfReportService pdf) => _pdf = pdf; /// PDF do faturamento por EAP do contrato. [HttpGet("contratos/{contratoId:guid}/faturamento/pdf")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task FaturamentoPdf( Guid contratoId, [FromServices] IFaturamentoService faturamento, CancellationToken ct = default) { var dados = await faturamento.GetFaturamentoAsync(contratoId, ct); var bytes = _pdf.Faturamento(dados); return File(bytes, "application/pdf", $"faturamento-{contratoId}.pdf"); } /// PDF do resumo de acompanhamento da obra na data. [HttpGet("obras/{obraId:guid}/acompanhamento/pdf")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task AcompanhamentoPdf( Guid obraId, [FromQuery] DateOnly data, [FromServices] IAcompanhamentoService acompanhamento, CancellationToken ct = default) { var foto = await acompanhamento.GetFotoAsync(obraId, data, ct); var historico = await acompanhamento.GetHistoricoAsync(obraId, ct); var bytes = _pdf.Acompanhamento(foto, historico); return File(bytes, "application/pdf", $"acompanhamento-{obraId}.pdf"); } /// PDF de um relatório técnico. [HttpGet("relatorios-tecnicos/{id:guid}/pdf")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task RelatorioTecnicoPdf( Guid id, [FromServices] IRelatorioTecnicoService relatorios, CancellationToken ct = default) { // GetByProducao/GetByObra retornam listas; aqui buscamos o RT específico pela obra dele. var rt = await relatorios.GetByIdAsync(id, ct); var bytes = _pdf.RelatorioTecnico(rt); return File(bytes, "application/pdf", $"relatorio-tecnico-{rt.Numero}.pdf"); } }