<?php
declare(strict_types=1);

namespace App\Core\Events;

final class SaleVoided extends Event
{
    public function __construct(
        public readonly int $saleId,
        public readonly string $reason,
    ) {}

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

    public function toArray(): array
    {
        return [
            'sale_id' => $this->saleId,
            'reason' => $this->reason,
        ];
    }

    public static function from(array $data): static
    {
        return new self(
            saleId: (int) ($data['sale_id'] ?? 0),
            reason: (string) ($data['reason'] ?? ''),
        );
    }
}
