<?php
declare(strict_types=1);

namespace App\Core\Events;

final class InstallmentPlanCreated extends Event
{
    public function __construct(
        public readonly int $planId,
        public readonly int $memberId,
        public readonly string $totalAmount,
    ) {}

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

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

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