<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Retry;

final class RetryStatistics
{
    public function __construct(
        private readonly int $attempted = 0,
        private readonly int $succeeded = 0,
        private readonly int $scheduled = 0,
        private readonly int $deadLettered = 0
    ) {}

    public function incrementAttempted(): self { return new self($this->attempted + 1, $this->succeeded, $this->scheduled, $this->deadLettered); }
    public function incrementSucceeded(): self { return new self($this->attempted, $this->succeeded + 1, $this->scheduled, $this->deadLettered); }
    public function incrementScheduled(): self { return new self($this->attempted, $this->succeeded, $this->scheduled + 1, $this->deadLettered); }
    public function incrementDeadLettered(): self { return new self($this->attempted, $this->succeeded, $this->scheduled, $this->deadLettered + 1); }

    public function toArray(): array
    {
        return [
            'attempted' => $this->attempted,
            'succeeded' => $this->succeeded,
            'scheduled' => $this->scheduled,
            'deadLettered' => $this->deadLettered,
        ];
    }
}
