<?php
/**
 * Orchestrator — Phase 8: Lightweight IE/HYBRID/AI Decision Layer
 *
 * Single responsibility: translate IE confidence into routing decision.
 *
 *   IE confidence ≥ 0.85  → 'IE'      (serve directly from InferenceEngine)
 *   IE confidence 0.60–0.84 → 'HYBRID' (IE answer + AI enrichment)
 *   IE confidence < 0.60   → 'AI'      (full AI call)
 *   No IE match             → 'AI'
 *
 * Gateway keeps all existing flow logic unchanged.
 * This class only provides the three-letter decision string.
 */
class Orchestrator
{
    public static function decide(?array $ie, string $q, array $context = []): string
    {
        if (!$ie) return 'AI';

        $confidence = $ie['confidence'] ?? 0;

        if ($confidence >= 0.85) return 'IE';
        if ($confidence >= 0.60) return 'HYBRID';

        return 'AI';
    }
}
