<?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\SupportCenterCheckSeverity;

/**
 * 安装后本地就绪自检：供 CLI 与系统接入中心展示「安装包是否具备官方接入能力」。
 */
final class SupportCenterPostInstallCheckService
{
    public function __construct(
        private readonly SupportCenterLocalChecks $localChecks,
        private readonly SupportCenterRemoteProbe $remoteProbe,
    ) {}

    public function run(bool $includeRemote = false): SupportCenterCheckReport
    {
        $rows = $this->localChecks->coreRows(releasePackageMode: false);

        if ($includeRemote) {
            $rows[] = $this->remoteProbe->probeRow();
        } else {
            $rows[] = new SupportCenterCheckRow(
                id: 'remote_connectivity',
                severity: SupportCenterCheckSeverity::Ok,
                label: '远程连通性探测已跳过（默认仅本地检查）',
                reasonCode: SupportCenterSelfCheckReasonCodes::REMOTE_PROBE_SKIPPED,
                detail: 'pass --remote to probe',
            );
        }

        return new SupportCenterCheckReport($rows);
    }

    public function isPackageReady(): bool
    {
        return $this->run(includeRemote: false)->isPackageReady();
    }

    public function packageReadinessMessage(): string
    {
        if ($this->isPackageReady()) {
            return (string) __('dberp.site_onboarding.package_readiness.ready');
        }

        return (string) __('dberp.site_onboarding.package_readiness.not_ready');
    }
}
