<?php

declare(strict_types=1);

namespace App\Framework\Retry\Events;

use App\Framework\Core\ValueObjects\Timestamp;
use Throwable;

/**
 * Event für jeden Retry-Versuch
 */
final readonly class RetryAttemptEvent
{
    public function __construct(
        public int $attempt,
        public int $maxAttempts,
        public ?Throwable $lastException,
        public array $context,
        public Timestamp $timestamp
    ) {
    }

    public function isFirstAttempt(): bool
    {
        return $this->attempt === 1;
    }

    public function isRetryAttempt(): bool
    {
        return $this->attempt > 1;
    }

    public function isLastAttempt(): bool
    {
        return $this->attempt >= $this->maxAttempts;
    }

    public function getOperationType(): ?string
    {
        return $this->context['operation_type'] ?? null;
    }
}
