<?php

declare(strict_types=1);

namespace App\Framework\Deployment\Pipeline\ValueObjects;

/**
 * Pipeline Execution Status
 *
 * Tracks the current status of a deployment pipeline execution.
 */
enum PipelineStatus: string
{
    case PENDING = 'pending';
    case RUNNING = 'running';
    case SUCCESS = 'success';
    case FAILED = 'failed';
    case ROLLED_BACK = 'rolled_back';
    case CANCELLED = 'cancelled';

    public function isTerminal(): bool
    {
        return match ($this) {
            self::SUCCESS, self::FAILED, self::ROLLED_BACK, self::CANCELLED => true,
            default => false,
        };
    }

    public function isSuccessful(): bool
    {
        return $this === self::SUCCESS;
    }

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

    public function getIcon(): string
    {
        return match ($this) {
            self::PENDING => '⏳',
            self::RUNNING => '🔄',
            self::SUCCESS => '✅',
            self::FAILED => '❌',
            self::ROLLED_BACK => '↩️',
            self::CANCELLED => '🚫',
        };
    }
}
