<?php

namespace App\Services;

class TriageService
{
    /**
     * Routing support only: never returns a diagnosis. Clinical protocols should
     * replace/extend these rules before real-world deployment.
     */
    public function route(string $complaint): array
    {
        $text = mb_strtolower($complaint);
        $emergencyTerms = ['unconscious','not breathing','severe bleeding','seizure','chest pain','stroke'];
        foreach ($emergencyTerms as $term) {
            if (str_contains($text, $term)) {
                return ['level'=>'emergency_flag','recommended_service'=>null,'message'=>'This request needs immediate emergency-service assessment rather than routine home-care dispatch.'];
            }
        }
        if (preg_match('/child|baby|infant|toddler|paediatric/', $text)) return ['level'=>'routine','recommended_service'=>'doctor-home-visit','message'=>'Route to a clinician suitable for child care.'];
        if (preg_match('/wound|dressing|injection|catheter/', $text)) return ['level'=>'routine','recommended_service'=>'nursing-care','message'=>'Route to qualified nursing care.'];
        if (preg_match('/rehab|mobility|physio|joint|exercise/', $text)) return ['level'=>'routine','recommended_service'=>'physiotherapy','message'=>'Route to physiotherapy.'];
        return ['level'=>'routine','recommended_service'=>'doctor-home-visit','message'=>'Route for general clinical assessment.'];
    }
}
