<?php

declare(strict_types=1);

namespace App\Services\SupportCenter;

/**
 * 更新失败上下文（不含密钥与 stack trace）。
 */
final class HostSystemUpdateFailureContext
{
    /**
     * @param  array<string, mixed>|null  $safeContext
     */
    public function __construct(
        public readonly string $failedStep,
        public readonly ?string $previousStatus,
        public readonly string $errorCode,
        public readonly string $userFacingMessage,
        public readonly bool $requiresRollback = true,
        public readonly ?string $exceptionClass = null,
        public readonly ?int $commandExitCode = null,
        public readonly ?array $safeContext = null,
    ) {}

    public function failedDuringOrAfterFileChanges(): bool
    {
        return in_array($this->failedStep, [
            'replace_files',
            'replace_vendor',
            'run_migrations',
            'clear_cache',
            'write_version',
            'maintenance_down',
            'maintenance_up',
        ], true);
    }
}
