<?php
declare(strict_types=1);

namespace App\Core\Events;

final class FineImposed extends Event
{
    public function __construct(
        public readonly int $fineId,
        public readonly int $memberId,
        public readonly string $penaltyType,
        public readonly string $amount,
    ) {}

    public static function eventName(): string
    {
        return 'fine.imposed';
    }

    public function toArray(): array
    {
        return [
            'fine_id' => $this->fineId,
            'member_id' => $this->memberId,
            'penalty_type' => $this->penaltyType,
            'amount' => $this->amount,
        ];
    }

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