<?php
declare(strict_types=1);

namespace App\Core\Events;

final class SubscriptionPaid extends Event
{
    public function __construct(
        public readonly int $subscriptionId,
        public readonly int $memberId,
        public readonly string $year,
        public readonly string $amount,
    ) {}

    public static function eventName(): string
    {
        return 'subscription.paid';
    }

    public function toArray(): array
    {
        return [
            'subscription_id' => $this->subscriptionId,
            'member_id' => $this->memberId,
            'year' => $this->year,
            'amount' => $this->amount,
        ];
    }

    public static function from(array $data): static
    {
        return new self(
            subscriptionId: (int) ($data['subscription_id'] ?? 0),
            memberId: (int) ($data['member_id'] ?? 0),
            year: (string) ($data['year'] ?? ''),
            amount: (string) ($data['amount'] ?? '0.00'),
        );
    }
}
