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

use boru\ai\AI;
use boru\ai\Bootstrap;
use boru\ai\Config\Config;
use boru\ai\Embedding\ArrayEmbeddingStore;
use boru\ai\Http\HttpResponse;
use boru\ai\Runtime\RuntimeContext;
use boru\ai\Tests\Fakes\FakeHttpClient;
use PHPUnit\Framework\TestCase;

abstract class IntegrationTestCase extends TestCase
{
    protected function setUp(): void
    {
        AI::runtimeContext(new RuntimeContext());
        AI::config(new Config());
    }

    protected function bootstrapWithHttpClients(FakeHttpClient $openAIHttpClient = null, FakeHttpClient $geminiHttpClient = null)
    {
        $config = new Config();
        $config->provider('openai', array(
            'api_key' => 'test-openai-key',
            'http_client' => $openAIHttpClient,
        ));
        $config->provider('gemini', array(
            'api_key' => 'test-gemini-key',
            'http_client' => $geminiHttpClient,
        ));
        $config->persistence(array(
            'enabled' => false,
        ));

        Bootstrap::registerDefaults($config);
        return $config;
    }

    protected function jsonResponse(array $payload, $statusCode = 200)
    {
        $response = new HttpResponse();
        $response->statusCode($statusCode);
        $response->body(json_encode($payload));
        return $response;
    }

    protected function installArrayEmbeddingStore()
    {
        $store = new ArrayEmbeddingStore();
        AI::embeddingStore($store);
        return $store;
    }
}
