<?php

declare(strict_types=1);

namespace App\Services\SupportCenter;

/**
 * 官方授权与服务状态 → 中文业务标签。
 */
final class HostSystemAuthorizationStatusPresenter
{
    public function authorizationLabel(bool $authorized): string
    {
        return $authorized
            ? (string) __('dberp.system_authorization.status.authorized')
            : (string) __('dberp.system_authorization.status.unauthorized');
    }

    public function authorizationBadgeColor(bool $authorized): string
    {
        return $authorized ? 'success' : 'gray';
    }

    public function serviceStatusLabel(?string $serviceStatus): string
    {
        $normalized = strtolower(trim((string) $serviceStatus));

        if ($normalized === '') {
            return (string) __('dberp.system_authorization.service_status.unknown');
        }

        $translationKey = 'dberp.system_authorization.service_status.'.$normalized;
        $label = __($translationKey);

        return $label !== $translationKey
            ? $label
            : (string) __('dberp.system_authorization.service_status.unknown');
    }

    public function serviceStatusBadgeColor(?string $serviceStatus): string
    {
        return match (strtolower(trim((string) $serviceStatus))) {
            'active' => 'success',
            'expired' => 'danger',
            'suspended' => 'warning',
            default => 'gray',
        };
    }

    public function syncStatusLabel(?string $syncStatus): string
    {
        return match (strtolower(trim((string) $syncStatus))) {
            'success' => (string) __('dberp.system_authorization.sync_status.success'),
            'failed' => (string) __('dberp.system_authorization.sync_status.failed'),
            default => (string) __('dberp.system_authorization.sync_status.never'),
        };
    }

    public function syncStatusBadgeColor(?string $syncStatus): string
    {
        return match (strtolower(trim((string) $syncStatus))) {
            'success' => 'success',
            'failed' => 'danger',
            default => 'gray',
        };
    }
}
