<?php

declare(strict_types=1);

namespace App\Services\SupportCenter;

use App\Enums\SupportCenter\HostSystemUpdateEnvironmentDiagnosticLevel;

/**
 * 单条系统更新环境诊断结果。
 */
final readonly class HostSystemUpdateEnvironmentDiagnosticItem
{
    public function __construct(
        public string $key,
        public string $label,
        public string $status,
        public HostSystemUpdateEnvironmentDiagnosticLevel $level,
        public string $message,
        public string $suggestion,
    ) {}

    public function isBlocking(): bool
    {
        return $this->level === HostSystemUpdateEnvironmentDiagnosticLevel::Blocking;
    }

    public function isWarning(): bool
    {
        return $this->level === HostSystemUpdateEnvironmentDiagnosticLevel::Warning;
    }

    /**
     * @return array{
     *     key: string,
     *     label: string,
     *     status: string,
     *     level: string,
     *     message: string,
     *     suggestion: string,
     *     blocking: bool,
     *     status_label: string,
     *     level_label: string,
     * }
     */
    public function toPanelArray(): array
    {
        return [
            'key' => $this->key,
            'label' => $this->label,
            'status' => $this->status,
            'level' => $this->level->value,
            'message' => $this->message,
            'suggestion' => $this->suggestion,
            'blocking' => $this->isBlocking(),
            'status_label' => (string) __('dberp.system_update_center.environment_diagnostics.status.'.$this->status),
            'level_label' => (string) __('dberp.system_update_center.environment_diagnostics.level.'.$this->level->value),
        ];
    }
}
