<?php

declare(strict_types=1);

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

namespace App\Support;

use App\Filament\Pages\HostSystemAuthorizationCenterPage;
use App\Filament\Pages\HostSystemUpdateCenterPage;
use App\Services\SupportCenter\HostSystemAuthorizationStatusPresenter;

/**
 * 官方授权与支撑连接摘要：只读统一字段，供系统信息、概览卡片等复用（不含密钥、令牌与原始 API 载荷）。
 */
final class HostSystemAuthorizationSummaryDisplay
{
    public function __construct(
        private readonly SiteOnboardingCenterDisplay $siteOnboardingDisplay,
        private readonly HostSystemAuthorizationCenterDisplay $authorizationCenterDisplay,
        private readonly HostSystemAuthorizationStatusPresenter $authorizationStatusPresenter,
        private readonly DberpProductVersion $productVersion,
    ) {}

    /**
     * @return array{
     *     is_site_bound: bool,
     *     authorization_status_label: string,
     *     authorization_status_color: string,
     *     license_edition_label: string,
     *     service_status_label: string,
     *     service_status_color: string,
     *     expires_at_label: string|null,
     *     remaining_days_label: string|null,
     *     support_connection_label: string,
     *     support_connection_color: string,
     *     authorization_center_url: string,
     *     system_update_center_url: string,
     * }
     */
    public function summary(): array
    {
        $record = $this->authorizationCenterDisplay->record();

        return [
            'is_site_bound' => $this->siteOnboardingDisplay->isBound(),
            'authorization_status_label' => $this->authorizationCenterDisplay->authorizationLabel(),
            'authorization_status_color' => $this->authorizationCenterDisplay->authorizationBadgeColor(),
            'license_edition_label' => $this->productVersion->publicProductEdition(),
            'service_status_label' => $this->authorizationCenterDisplay->serviceStatusLabel(),
            'service_status_color' => $this->authorizationStatusPresenter->serviceStatusBadgeColor($record->service_status),
            'expires_at_label' => $this->authorizationCenterDisplay->expiresAtLabel(),
            'remaining_days_label' => $this->authorizationCenterDisplay->remainingServiceDaysLabel(),
            'support_connection_label' => $this->siteOnboardingDisplay->localReadinessLabel(),
            'support_connection_color' => $this->siteOnboardingDisplay->localReadinessBadgeColor(),
            'authorization_center_url' => HostSystemAuthorizationCenterPage::getUrl(panel: 'admin'),
            'system_update_center_url' => HostSystemUpdateCenterPage::getUrl(panel: 'admin'),
        ];
    }
}
