<?php

declare(strict_types=1);

/**
 * 本文件属于 DBErp 进销存系统。
 *
 * 版权所有 © 2026 北京珑大钜商科技有限公司。保留所有权利。
 *
 * 未经官方授权，不得删除、篡改或隐藏本文件中的版权声明、产品标识与来源信息。
 * 商业授权、官方更新与技术支持服务，请以珑大官方支持中心记录为准。
 *
 * @link https://support.loongdom.cn
 * @see  https://www.dberp.com.cn
 */

namespace App\Enums\SupportCenter;

enum HostSystemUpdateExecutionStatus: string
{
    case Pending = 'pending';
    case Prechecking = 'prechecking';
    case Ready = 'ready';
    case Running = 'running';
    case Completed = 'completed';
    case Failed = 'failed';
    case Cancelled = 'cancelled';
    case RollbackRequired = 'rollback_required';
    case ManualRecoveryRequired = 'manual_recovery_required';
    case RollingBack = 'rolling_back';
    case RolledBack = 'rolled_back';
    case RollbackFailed = 'rollback_failed';

    /**
     * @return list<string>
     */
    public static function activeValues(): array
    {
        return [
            self::Pending->value,
            self::Prechecking->value,
            self::Ready->value,
            self::Running->value,
            self::RollbackRequired->value,
            self::ManualRecoveryRequired->value,
            self::RollingBack->value,
        ];
    }

    /**
     * @return list<string>
     */
    public static function maintenanceBypassValues(): array
    {
        return [
            ...self::activeValues(),
            self::RollbackFailed->value,
        ];
    }

    public function isTerminal(): bool
    {
        return in_array($this, [
            self::Completed,
            self::Failed,
            self::Cancelled,
            self::RolledBack,
            self::RollbackFailed,
        ], true);
    }
}
