<?php
declare(strict_types=1);

namespace App\Core\Events;

final class PaymentVoided extends Event
{
    public function __construct(
        public readonly int $paymentId,
        public readonly int $memberId,
        public readonly string $paymentType,
        public readonly string $amount,
        public readonly string $reason,
    ) {}

    public static function eventName(): string
    {
        return 'payment.voided';
    }

    public function toArray(): array
    {
        return [
            'payment_id' => $this->paymentId,
            'member_id' => $this->memberId,
            'payment_type' => $this->paymentType,
            'amount' => $this->amount,
            'reason' => $this->reason,
        ];
    }

    public static function from(array $data): static
    {
        return new self(
            paymentId: (int) ($data['payment_id'] ?? 0),
            memberId: (int) ($data['member_id'] ?? 0),
            paymentType: (string) ($data['payment_type'] ?? ''),
            amount: (string) ($data['amount'] ?? '0.00'),
            reason: (string) ($data['reason'] ?? ''),
        );
    }
}
