<?php
namespace boru\ai\Tests\AI;

use boru\ai\AI;
use boru\ai\Config\Config;
use boru\ai\Embedding\ArrayEmbeddingStore;
use boru\ai\Provider\ProviderRegistry;
use boru\ai\Runtime\RuntimeContext;
use boru\ai\Tests\Fakes\FakeProvider;
use PHPUnit\Framework\TestCase;

class AIEmbeddingFacadeTest extends TestCase
{
    protected function setUp(): void
    {
        AI::runtimeContext(new RuntimeContext());

        $registry = new ProviderRegistry();
        $registry->register(new FakeProvider());
        $registry->mapModelPrefix('fake-', 'fake');
        AI::registry($registry);
        AI::embeddingStore(new ArrayEmbeddingStore());

        $config = new Config();
        $config->defaults(array(
            'provider' => 'fake',
        ));
        $config->provider('fake', array(
            'vector' => array(
                'model' => 'fake-embedding-1',
            ),
        ));
        AI::config($config);
    }

    public function testFacadeEmbedUsesConfiguredProviderAndModel()
    {
        $result = AI::provider('fake')->embed('hello there');

        $this->assertSame('fake', $result->provider());
        $this->assertSame('fake-embedding-1', $result->model());
        $this->assertSame(array(1.0, 11.0), $result->vector());
    }

    public function testFacadeEmbeddingsAcceptsMultipleInputs()
    {
        $result = AI::provider('fake')->model('fake-embedding-2')->embeddings(array('a', 'bb'));

        $this->assertCount(2, $result->embeddings());
        $this->assertSame(array(2.0, 2.0), $result->vector(1));
    }
}
