<?php
declare(strict_types=1);

namespace App\Core\Events;

final class SaleCompleted extends Event
{
    public function __construct(
        public readonly int $saleId,
        public readonly string $invoiceNumber,
        public readonly string $customerType,
        public readonly string $totalAmount,
    ) {}

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

    public function toArray(): array
    {
        return [
            'sale_id' => $this->saleId,
            'invoice_number' => $this->invoiceNumber,
            'customer_type' => $this->customerType,
            'total_amount' => $this->totalAmount,
        ];
    }

    public static function from(array $data): static
    {
        return new self(
            saleId: (int) ($data['sale_id'] ?? 0),
            invoiceNumber: (string) ($data['invoice_number'] ?? ''),
            customerType: (string) ($data['customer_type'] ?? ''),
            totalAmount: (string) ($data['total_amount'] ?? '0.00'),
        );
    }
}
