<?php
namespace boru\ai\Tests\Provider\Gemini;

use boru\ai\AI;
use boru\ai\Provider\Gemini\GeminiMapper;
use boru\ai\Provider\Gemini\GeminiProvider;
use boru\ai\Runtime\RuntimeContext;
use boru\ai\Tests\Fakes\FakeGeminiClient;
use PHPUnit\Framework\TestCase;

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

    public function testAiFacadeRunsSimpleGeminiRequestAndReturnsTextResponse()
    {
        $client = new FakeGeminiClient(array(
            array(
                'responseId' => 'gem_resp_simple_1',
                'modelVersion' => 'gemini-2.5-pro',
                'candidates' => array(
                    array(
                        'content' => array(
                            'parts' => array(
                                array(
                                    'text' => 'Message received! Everything appears to be working correctly.',
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ));

        $provider = new GeminiProvider($client, new GeminiMapper());
        AI::registry()->register($provider);

        $response = AI::provider('gemini')
            ->model('gemini-2.5-pro')
            ->reference('simple_example_test')
            ->addMessage('This is a simple test message.')
            ->run();

        $this->assertSame('Message received! Everything appears to be working correctly.', $response->text());
        $this->assertSame('generateContent', $client->requests[0]['method']);
        $this->assertSame('gemini-2.5-pro', $client->requests[0]['model']);
        $this->assertSame('user', $client->requests[0]['payload']['contents'][0]['role']);
        $this->assertSame('This is a simple test message.', $client->requests[0]['payload']['contents'][0]['parts'][0]['text']);
    }
}
