<?php

declare(strict_types=1);

namespace Plugin\tnt_mcp\src\Mcp\Health;

/**
 * Traffic-light state of a single {@see Signal}, and the only input to the `shop_health` verdict.
 *
 * Three values, deliberately: an LLM asked to reason over a five-point severity scale invents
 * thresholds. Green/amber/red maps 1:1 onto "ignore / look / act".
 */
enum HealthStatus: string
{
    case Green = 'green';
    case Amber = 'amber';
    case Red   = 'red';

    /**
     * Roll-up rule, pinned by test: one red makes the whole shop `unhealthy`, any amber makes it
     * `degraded`, everything green is `healthy`. A scheduled job alerts on this single word, so it
     * must never be derived from counts or percentages that shift as the shop grows.
     */
    public static function verdict(HealthStatus ...$statuses): string
    {
        $verdict = 'healthy';
        foreach ($statuses as $status) {
            if ($status === self::Red) {
                return 'unhealthy';
            }
            if ($status === self::Amber) {
                $verdict = 'degraded';
            }
        }

        return $verdict;
    }
}
