<?php

declare(strict_types=1);

namespace App\Services\SupportCenter;

/**
 * 系统更新环境诊断汇总。
 */
final readonly class HostSystemUpdateEnvironmentDiagnosticReport
{
    /**
     * @param  list<HostSystemUpdateEnvironmentDiagnosticItem>  $items
     */
    public function __construct(
        public array $items,
        public bool $canRunBrowserUpdate,
        public int $blockingCount,
        public int $warningCount,
        public string $summaryMessage,
    ) {}

    /**
     * @return list<array<string, mixed>>
     */
    public function itemsForPanel(): array
    {
        return array_map(
            static fn (HostSystemUpdateEnvironmentDiagnosticItem $item): array => $item->toPanelArray(),
            $this->items,
        );
    }

    public function firstBlockingSummary(): ?string
    {
        foreach ($this->items as $item) {
            if ($item->isBlocking()) {
                return $item->label.'：'.$item->message;
            }
        }

        return null;
    }
}
