<?php

declare(strict_types=1);

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

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),
        ];
    }
}
