<?php

declare(strict_types=1);

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');
    }
}
