<?php

namespace Modules\AiCore\Tests\Unit;

use Modules\AiCore\Entities\AiPrompts;
use Modules\AiCore\Entities\Verticals\VerticalCatalog;
use PHPUnit\Framework\TestCase;

/**
 * AiPrompts is the single source of truth for the editable system prompts and
 * makes the generalizable "clean the dictation" task business-type aware: the
 * SAME key yields a vet / clinic / automotive scribe prompt purely from the
 * selected vertical. Pure — no DB / LLM.
 */
class AiPromptsTest extends TestCase
{
    public function test_specialized_key_returns_its_static_default(): void
    {
        $soap = AiPrompts::default('vet.soap');
        $this->assertStringContainsString('SOAP', $soap);
        $this->assertStringContainsString('subjective', $soap); // JSON contract key
    }

    public function test_unknown_key_returns_empty_string(): void
    {
        $this->assertSame('', AiPrompts::default('no.such.key'));
    }

    public function test_clinic_assist_keeps_specialty_placeholder(): void
    {
        // The {specialty} token must survive so the call site can substitute it.
        $this->assertStringContainsString('{specialty}', AiPrompts::default('clinic.assist'));
    }

    public function test_clean_prompt_is_vertical_aware_for_vet(): void
    {
        $prompt = AiPrompts::default('vet.clean', VerticalCatalog::get('vet_clinic'));
        $this->assertStringContainsString('veterinary scribe editor', $prompt);
        $this->assertStringContainsString('pet', $prompt);
        $this->assertStringContainsString('drug names, doses', $prompt); // a vet keep item
    }

    public function test_clean_prompt_is_vertical_aware_for_medical(): void
    {
        $prompt = AiPrompts::default('clinic.clean', VerticalCatalog::get('medical_clinic'));
        $this->assertStringContainsString('clinical scribe editor', $prompt);
        $this->assertStringContainsString('patient', $prompt);
    }

    public function test_same_clean_key_adapts_to_automotive(): void
    {
        // The vet.clean KEY, but an automotive vertical -> a vehicle-service prompt:
        // the behaviour follows the business type, not the key.
        $prompt = AiPrompts::default('vet.clean', VerticalCatalog::get('automotive'));
        $this->assertStringContainsString('automotive service-advisor scribe', $prompt);
        $this->assertStringContainsString('vehicle', $prompt);
        $this->assertStringNotContainsString('veterinary scribe editor', $prompt);
    }

    public function test_grouped_exposes_settings_groups(): void
    {
        $grouped = AiPrompts::grouped();
        $this->assertArrayHasKey('Vet appointment', $grouped);
        $this->assertArrayHasKey('Human clinic', $grouped);
        $this->assertArrayHasKey('vet.clean', $grouped['Vet appointment']);
    }
}
