<?php

declare(strict_types=1);

namespace App\Framework\EventSourcing\Sagas;

/**
 * Saga Status Enum
 *
 * Represents the current status of a saga execution
 */
enum SagaStatus: string
{
    case RUNNING = 'running';
    case COMPLETED = 'completed';
    case FAILED = 'failed';
    case COMPENSATING = 'compensating';
    case COMPENSATED = 'compensated';

    public function isTerminal(): bool
    {
        return in_array($this, [
            self::COMPLETED,
            self::FAILED,
            self::COMPENSATED,
        ], true);
    }

    public function canCompensate(): bool
    {
        return $this === self::FAILED;
    }
}
