using AutoMapper;
using DocumentOperator.Application.Common.DTOs;
using DocumentOperator.Application.Common.Interfaces;
using MediatR;
namespace DocumentOperator.Application.ValidatePdfA.Queries;
///
/// Query for PDF/A validation (Stream-based)
///
public record ValidatePdfAQuery : IRequest
{
///
/// PDF as stream (caller is responsible for disposal)
///
public required Stream PdfStream { get; init; }
}
///
/// Handler for ValidatePdfAQuery
/// Orchestrates PDF/A validation using IPdfProcessor and AutoMapper
///
public class ValidatePdfAQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper)
: IRequestHandler
{
///
/// Validates PDF/A and returns metadata with conformance level
///
public async Task Handle(ValidatePdfAQuery request, CancellationToken cancellationToken)
{
// Call DevExpress service directly with stream (exceptions propagate naturally)
var metadata = await PdfProcessor.ValidatePdfAAsync(request.PdfStream);
// Map DTO to response DTO using AutoMapper
return Mapper.Map(metadata);
}
}