using DocumentService.Application.Common.DTOs; using DocumentService.Client.Interfaces; using DocumentService.Client.Models.Results; namespace DocumentService.Client.Clients; /// /// Orchestrated multi-step workflows that compose multiple DocumentService clients /// into single, higher-level operations. /// public class WorkflowsClient(IPdfValidationClient validation, ISwissQrCodeClient swissQrCode) : IWorkflowsClient { /// public async Task InspectSwissQrCodeAsync( byte[] pdfBytes, bool raw = false, CancellationToken cancellationToken = default) { var validationResult = await validation.ValidateAsync(pdfBytes, cancellationToken); var qrCode = validationResult.IsValid ? await swissQrCode.ExtractAsync(pdfBytes, raw, cancellationToken) : null; return new SwissQrCodeResult(qrCode, validationResult); } /// public async Task InspectSwissQrCodeAsync( Stream pdfStream, bool raw = false, CancellationToken cancellationToken = default) { var validationResult = await validation.ValidateAsync(pdfStream, cancellationToken); if (!validationResult.IsValid) return new SwissQrCodeResult(null, validationResult); // Stream was consumed by validation – reset if possible, otherwise re-open is caller's responsibility. if (pdfStream.CanSeek) pdfStream.Position = 0; var qrCode = await swissQrCode.ExtractAsync(pdfStream, raw, cancellationToken); return new SwissQrCodeResult(qrCode, validationResult); } } /// /// Convenience extensions for that accept a file path as input. /// Defined alongside so they are discoverable without an additional using directive. /// public static class WorkflowsClientExtensions { /// /// Validates the PDF at and attempts Swiss QR Code extraction /// in a single call. Opens a and delegates to /// . /// /// The workflows client. /// Absolute or relative path to the PDF file. /// /// false (default) – returns a parsed Bill object.
/// true – returns raw QR text lines without parsing. /// /// Cancellation token. public static async Task InspectSwissQrCodeAsync( this IWorkflowsClient client, string filePath, bool raw = false, CancellationToken cancellationToken = default) { using var stream = File.OpenRead(filePath); return await client.InspectSwissQrCodeAsync(stream, raw, cancellationToken); } }