<?php

namespace Modules\AiCore\Tests\Unit;

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

/**
 * The vertical catalog drives the business-type-aware AI behaviour: choosing a
 * "Business Type" in AI Settings must swap in the right scribe role, subject and
 * "what to keep" framing. Pure data — verified without a DB or the framework.
 */
class VerticalCatalogTest extends TestCase
{
    public function test_unknown_or_empty_key_falls_back_to_general(): void
    {
        $this->assertSame('general', VerticalCatalog::get(null)->key);
        $this->assertSame('general', VerticalCatalog::get('')->key);
        $this->assertSame('general', VerticalCatalog::get('does_not_exist')->key);
    }

    public function test_is_valid_distinguishes_known_keys(): void
    {
        $this->assertInstanceOf(VerticalProfile::class, VerticalCatalog::get('vet_clinic'));
        $this->assertTrue(VerticalCatalog::isValid('vet_clinic'));
        $this->assertFalse(VerticalCatalog::isValid('nope'));
        $this->assertFalse(VerticalCatalog::isValid(null));
    }

    public function test_vet_clinic_profile_is_veterinary(): void
    {
        $vp = VerticalCatalog::get('vet_clinic');
        $this->assertSame('veterinary scribe editor', $vp->scribeRole);
        $this->assertStringContainsString('pet', $vp->subject);
        $this->assertStringContainsString('veterinary', $vp->assistant);
        $this->assertContains('Vaccination / test recommendations', $vp->keep);
    }

    public function test_medical_clinic_profile_is_human_clinical(): void
    {
        $vp = VerticalCatalog::get('medical_clinic');
        $this->assertSame('clinical scribe editor', $vp->scribeRole);
        $this->assertSame('patient', $vp->subject);
        $this->assertStringContainsString('clinical', $vp->assistant);
    }

    public function test_automotive_profile_is_vehicle_not_medical(): void
    {
        $vp = VerticalCatalog::get('automotive');
        $this->assertSame('vehicle', $vp->subject);
        $this->assertStringContainsString('automotive', $vp->scribeRole);

        $keep = strtolower(implode(' ', $vp->keep));
        $this->assertStringContainsString('fault', $keep);
        $this->assertStringNotContainsString('vaccination', $keep);
    }

    public function test_keep_list_falls_back_to_generic_when_unset(): void
    {
        // pharmacy defines no keep[] -> the generic 3-bullet fallback applies.
        $vp = VerticalCatalog::get('pharmacy');
        $this->assertSame([], $vp->keep);
        $this->assertCount(3, $vp->keepList());
        $this->assertStringContainsString('substantive', strtolower($vp->keepList()[0]));
    }

    public function test_options_render_emoji_labels(): void
    {
        $options = VerticalCatalog::options();
        $this->assertArrayHasKey('vet_clinic', $options);
        $this->assertStringContainsString('Veterinary', $options['vet_clinic']);
    }
}
