using AutoMapper;
using DocumentOperator.Application.Common.DTOs;
using DocumentOperator.Application.Common.Interfaces;
using MediatR;
namespace DocumentOperator.Application.CheckPdfAttachments.Queries;
///
/// Query for checking PDF attachments (Stream-based)
///
public record CheckPdfAttachmentsQuery : IRequest
{
///
/// PDF as stream (caller is responsible for disposal)
///
public required Stream PdfStream { get; init; }
}
///
/// Handler for CheckPdfAttachmentsQuery
/// Orchestrates PDF attachment checking using IPdfProcessor and AutoMapper
///
public class CheckPdfAttachmentsQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper)
: IRequestHandler
{
///
/// Checks PDF attachments and returns detailed metadata
///
public async Task Handle(CheckPdfAttachmentsQuery request, CancellationToken cancellationToken)
{
// Call DevExpress service directly with stream (exceptions propagate naturally)
var attachmentInfo = await PdfProcessor.CheckAttachmentsAsync(request.PdfStream);
// Map DTO to response DTO using AutoMapper
return Mapper.Map(attachmentInfo);
}
}