using AutoMapper; using DocumentOperator.Application.Common.DTOs; using DocumentOperator.Application.Common.Interfaces; using MediatR; namespace DocumentOperator.Application.ValidatePdf.Queries; /// /// Query for PDF validation (supports both byte array and Base64 input) /// public record ValidatePdfQuery : IRequest { /// /// PDF as byte array (direct upload) /// public byte[]? PdfBytes { get; init; } /// /// PDF as Base64 string (API clients) /// public string? Base64Pdf { get; init; } } /// /// Handler for ValidatePdfQuery /// Orchestrates PDF validation using IPdfProcessor and AutoMapper /// public class ValidatePdfQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper) : IRequestHandler { /// /// Validates PDF and returns metadata /// public async Task Handle(ValidatePdfQuery request, CancellationToken cancellationToken) { // Use byte[] if available, otherwise convert Base64 byte[] pdfBytes = request.PdfBytes ?? Convert.FromBase64String(request.Base64Pdf!); // Call DevExpress service (can throw PdfProcessingException) var metadata = await PdfProcessor.ValidateAsync(pdfBytes); // Map domain entity to DTO using AutoMapper return Mapper.Map(metadata); } }