<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Retry;

final class RetryResult
{
    public function __construct(
        private readonly bool $ok,
        private readonly bool $retryScheduled,
        private readonly bool $deadLettered,
        private readonly int $delaySeconds = 0,
        private readonly string $message = ''
    ) {}

    public static function success(string $message = 'success'): self { return new self(true, false, false, 0, $message); }
    public static function retry(int $delaySeconds, string $message = 'retry scheduled'): self { return new self(false, true, false, $delaySeconds, $message); }
    public static function deadLetter(string $message = 'dead lettered'): self { return new self(false, false, true, 0, $message); }

    public function ok(): bool { return $this->ok; }
    public function retryScheduled(): bool { return $this->retryScheduled; }
    public function deadLettered(): bool { return $this->deadLettered; }
    public function delaySeconds(): int { return $this->delaySeconds; }

    public function toArray(): array
    {
        return [
            'ok' => $this->ok,
            'retryScheduled' => $this->retryScheduled,
            'deadLettered' => $this->deadLettered,
            'delaySeconds' => $this->delaySeconds,
            'message' => $this->message,
        ];
    }
}
