<?php
declare(strict_types=1);

namespace Itdatex\Rechnungseingang;

if ( ! defined( 'ABSPATH' ) ) { exit; }

use DateTimeInterface;

/**
 * Reines Daten-Objekt mit den Kernfeldern einer E-Rechnung.
 *
 * Bewusst flach gehalten — nur die Felder, die fuer Buchung,
 * Anzeige und Faelligkeitslogik gebraucht werden. Vollstaendige
 * Rohstruktur landet bei Bedarf in raw_meta.
 */
final class InvoiceData
{
    use InvoiceDataWith;

    public function __construct(
        public readonly Format $format,
        public readonly ?string $invoiceNumber = null,
        public readonly ?DateTimeInterface $issueDate = null,
        public readonly ?DateTimeInterface $dueDate = null,
        public readonly ?string $sellerName = null,
        public readonly ?string $sellerVatId = null,
        public readonly ?string $buyerName = null,
        public readonly ?string $buyerReference = null,
        public readonly ?float $totalNet = null,
        public readonly ?float $totalTax = null,
        public readonly ?float $totalGross = null,
        public readonly string $currency = 'EUR',
        public readonly int $lineCount = 0,
    ) {}

    public function toArray(): array
    {
        return [
            'format'          => $this->format->value,
            'invoice_number'  => $this->invoiceNumber,
            'issue_date'      => $this->issueDate?->format('Y-m-d'),
            'due_date'        => $this->dueDate?->format('Y-m-d'),
            'seller_name'     => $this->sellerName,
            'seller_vat_id'   => $this->sellerVatId,
            'buyer_name'      => $this->buyerName,
            'buyer_reference' => $this->buyerReference,
            'total_net'       => $this->totalNet,
            'total_tax'       => $this->totalTax,
            'total_gross'     => $this->totalGross,
            'currency'        => $this->currency,
            'line_count'      => $this->lineCount,
        ];
    }
}
