<?php

declare(strict_types=1);

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