<?php
declare(strict_types=1);

namespace App\Core\Events;

final class PayrollPaid extends Event
{
    public function __construct(
        public readonly int $payrollRunId,
        public readonly int $periodId,
        public readonly string $paymentDate,
    ) {}

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

    public function toArray(): array
    {
        return [
            'payroll_run_id' => $this->payrollRunId,
            'period_id' => $this->periodId,
            'payment_date' => $this->paymentDate,
        ];
    }

    public static function from(array $data): static
    {
        return new self(
            payrollRunId: (int) ($data['payroll_run_id'] ?? 0),
            periodId: (int) ($data['period_id'] ?? 0),
            paymentDate: (string) ($data['payment_date'] ?? ''),
        );
    }
}
