<?php

namespace App\Data;

use Spatie\LaravelData\Data;

class PaymentReceiptData extends Data
{
    public function __construct(
        public int $payment_id,
        public string $receipt_number,
        public string $issued_date,
        public ?string $pdf_url = null,
    ) {}

    public static function fromPaymentReceipt(\App\Models\PaymentReceipt $receipt): self
    {
        return new self(
            payment_id: $receipt->payment_id,
            receipt_number: $receipt->receipt_number,
            issued_date: $receipt->issued_date->format('Y-m-d H:i:s'),
            pdf_url: $receipt->pdf_url,
        );
    }

    public function toArray(): array
    {
        return [
            'payment_id' => $this->payment_id,
            'receipt_number' => $this->receipt_number,
            'issued_date' => $this->issued_date,
            'pdf_url' => $this->pdf_url,
        ];
    }
}
