<?php

declare(strict_types=1);

namespace App\Services\Install;

final class WebInstallPhaseTracker
{
    private WebInstallPhase $phase = WebInstallPhase::CheckingDatabase;

    public function enter(WebInstallPhase $phase): void
    {
        $this->phase = $phase;
    }

    public function current(): WebInstallPhase
    {
        return $this->phase;
    }

    public function hasReached(WebInstallPhase $milestone): bool
    {
        $currentIndex = array_search($this->phase, WebInstallPhase::ordered(), true);
        $milestoneIndex = array_search($milestone, WebInstallPhase::ordered(), true);

        if ($currentIndex === false || $milestoneIndex === false) {
            return false;
        }

        return $currentIndex >= $milestoneIndex;
    }
}
