<?php

declare(strict_types=1);

namespace App\Enums\SupportCenter;

/**
 * Web 分步更新阶段（每阶段对应一次 run-next-step 请求）。
 */
enum HostSystemUpdateStepPhase: string
{
    case BootstrapCheck = 'bootstrap_check';
    case BootstrapDownload = 'bootstrap_download';
    case BootstrapParse = 'bootstrap_parse';
    case BootstrapCreateExecution = 'bootstrap_create_execution';
    case MaintenanceDown = 'maintenance_down';
    case Precheck = 'precheck';
    case ExtractStaging = 'extract_staging';
    case Backup = 'backup';
    case ReplaceFiles = 'replace_files';
    case ReplaceVendor = 'replace_vendor';
    case MigrateBatch = 'migrate_batch';
    case ClearCache = 'clear_cache';
    case WriteVersion = 'write_version';
    case Complete = 'complete';

    public function next(): ?self
    {
        return match ($this) {
            self::BootstrapCheck => self::BootstrapDownload,
            self::BootstrapDownload => self::BootstrapParse,
            self::BootstrapParse => self::BootstrapCreateExecution,
            self::BootstrapCreateExecution => self::MaintenanceDown,
            self::MaintenanceDown => self::Precheck,
            self::Precheck => self::ExtractStaging,
            self::ExtractStaging => self::Backup,
            self::Backup => self::ReplaceFiles,
            self::ReplaceFiles => self::ReplaceVendor,
            self::ReplaceVendor => self::MigrateBatch,
            self::MigrateBatch => self::ClearCache,
            self::ClearCache => self::WriteVersion,
            self::WriteVersion => self::Complete,
            self::Complete => null,
        };
    }

    public function isBootstrap(): bool
    {
        return match ($this) {
            self::BootstrapCheck,
            self::BootstrapDownload,
            self::BootstrapParse,
            self::BootstrapCreateExecution => true,
            default => false,
        };
    }

    public function labelKey(): string
    {
        return 'dberp.system_update_center.step_phases.'.$this->value;
    }
}
