<?php

declare(strict_types=1);

namespace App\Services\SupportCenter;

/**
 * 系统更新执行步骤 → 中文业务标签。
 */
final class HostSystemUpdateStepPresenter
{
    public function label(?string $step): string
    {
        $normalized = strtolower(trim((string) $step));

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

        $translationKey = 'dberp.system_update_center.step.'.$normalized;
        $label = __($translationKey);

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

    public function logStatusLabel(?string $status): string
    {
        return match (strtolower(trim((string) $status))) {
            'started' => (string) __('dberp.system_update_center.log_status.started'),
            'completed' => (string) __('dberp.system_update_center.log_status.completed'),
            'failed' => (string) __('dberp.system_update_center.log_status.failed'),
            'skipped' => (string) __('dberp.system_update_center.log_status.skipped'),
            'transition' => (string) __('dberp.system_update_center.log_status.transition'),
            default => (string) __('dberp.system_update_center.log_status.unknown'),
        };
    }

    public function logStatusBadgeColor(?string $status): string
    {
        return match (strtolower(trim((string) $status))) {
            'completed' => 'success',
            'failed' => 'danger',
            'started' => 'info',
            'skipped' => 'gray',
            'transition' => 'warning',
            default => 'gray',
        };
    }
}
