<?php

declare(strict_types=1);

namespace App\Framework\Queue\Events;

use App\Framework\Core\ValueObjects\Timestamp;

final readonly class JobChainFailedEvent
{
    public Timestamp $timestamp;

    public function __construct(
        public string $chainId,
        public string $name,
        public string $failedJobId,
        public string $failedAt,
        ?Timestamp $timestamp = null
    ) {
        $this->timestamp = $timestamp ?? Timestamp::now();
    }

    public function getEventData(): array
    {
        return [
            'event_type' => 'job_chain_failed',
            'chain_id' => $this->chainId,
            'name' => $this->name,
            'failed_job_id' => $this->failedJobId,
            'failed_at' => $this->failedAt,
            'timestamp' => $this->timestamp->toFloat(),
        ];
    }
}
