using Books.Api.Invoicing.Pdf;
using GraphQL.Types;

namespace Books.Api.GraphQL.Types;

/// <summary>
/// GraphQL type for invoice PDF generation result.
/// </summary>
public class InvoicePdfResultGraphType : ObjectGraphType<InvoicePdfResult>
{
    public InvoicePdfResultGraphType()
    {
        Name = "InvoicePdfResult";
        Description = "Result of invoice PDF generation";

        Field(x => x.Success).Description("Whether the PDF was generated successfully");

        Field<StringGraphType>("pdfBase64")
            .Description("Base64-encoded PDF bytes (null if failed)")
            .Resolve(ctx => ctx.Source.PdfBytes != null
                ? Convert.ToBase64String(ctx.Source.PdfBytes)
                : null);

        Field(x => x.FileName, nullable: true).Description("Suggested filename for the PDF");
        Field(x => x.ErrorCode, nullable: true).Description("Error code if generation failed");
        Field(x => x.ErrorMessage, nullable: true).Description("Error message if generation failed");
    }
}
