namespace Books.Api.Invoicing.Pdf;

/// <summary>
/// Service for generating invoice PDFs with data fetching orchestration.
/// </summary>
public interface IInvoicePdfService
{
    /// <summary>
    /// Generates a PDF for the specified invoice.
    /// </summary>
    /// <param name="invoiceId">The invoice ID</param>
    /// <param name="ct">Cancellation token</param>
    /// <returns>Result containing PDF bytes or error information</returns>
    Task<InvoicePdfResult> GenerateAsync(string invoiceId, CancellationToken ct = default);
}

/// <summary>
/// Result of PDF generation operation.
/// </summary>
public record InvoicePdfResult
{
    public bool Success { get; init; }
    public byte[]? PdfBytes { get; init; }
    public string? FileName { get; init; }
    public string? ErrorCode { get; init; }
    public string? ErrorMessage { get; init; }

    public static InvoicePdfResult Succeeded(byte[] pdfBytes, string fileName) =>
        new() { Success = true, PdfBytes = pdfBytes, FileName = fileName };

    public static InvoicePdfResult Failed(string errorCode, string errorMessage) =>
        new() { Success = false, ErrorCode = errorCode, ErrorMessage = errorMessage };
}
