<?php
declare(strict_types=1);

namespace App\Core\Events;

final class InstallmentPaid extends Event
{
    public function __construct(
        public readonly int $planId,
        public readonly int $scheduleId,
        public readonly int $memberId,
    ) {}

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

    public function toArray(): array
    {
        return [
            'plan_id' => $this->planId,
            'schedule_id' => $this->scheduleId,
            'member_id' => $this->memberId,
        ];
    }

    public static function from(array $data): static
    {
        return new self(
            planId: (int) ($data['plan_id'] ?? 0),
            scheduleId: (int) ($data['schedule_id'] ?? 0),
            memberId: (int) ($data['member_id'] ?? 0),
        );
    }
}
