#nullable enable
using Baya.Application.Models.Invoices;
using Baya.Domain.Entities.Invoices;

namespace Baya.Application.Features.Invoices;

/// <summary>Maps an <see cref="Invoice"/> to its wire DTO, stringifying every IRR amount per the money
/// convention. The <paramref name="pdfUrl"/> is resolved by the handler through <c>IObjectStorage</c>.</summary>
internal static class InvoiceDtoFactory
{
    public static InvoiceDto FromEntity(Invoice invoice, string? pdfUrl) => new(
        invoice.Id,
        invoice.BookingId,
        invoice.InvoiceNumber,
        invoice.IssuingEntityType,
        invoice.GrossIrr.ToString(),
        invoice.PlatformCommissionIrr.ToString(),
        invoice.BnplCommissionIrr?.ToString(),
        invoice.VatRate,
        invoice.VatIrr.ToString(),
        (invoice.PlatformCommissionIrr + (invoice.BnplCommissionIrr ?? 0) + invoice.VatIrr).ToString(),
        invoice.MoadianReferenceNumber,
        invoice.MoadianStatus,
        pdfUrl,
        invoice.IssuedAt);
}
