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

class FakeGeminiClient extends \boru\ai\Provider\Gemini\GeminiClient
{
    /** @var array */
    public $requests = array();

    /** @var array */
    public $queuedResponses = array();

    public function __construct(array $queuedResponses = array())
    {
        $this->queuedResponses = $queuedResponses;
        parent::__construct('test-key', array(), new FakeHttpClient());
    }

    public function queueResponse(array $response)
    {
        $this->queuedResponses[] = $response;
        return $this;
    }

    public function generateContent($model, array $payload)
    {
        $this->requests[] = array(
            'method' => 'generateContent',
            'model' => $model,
            'payload' => $payload,
        );

        if (empty($this->queuedResponses)) {
            throw new \RuntimeException('No queued fake Gemini response');
        }

        return array_shift($this->queuedResponses);
    }

    public function embedContent($model, array $payload)
    {
        $this->requests[] = array(
            'method' => 'embedContent',
            'model' => $model,
            'payload' => $payload,
        );

        if (empty($this->queuedResponses)) {
            throw new \RuntimeException('No queued fake Gemini response');
        }

        return array_shift($this->queuedResponses);
    }

    public function batchEmbedContents($model, array $payload)
    {
        $this->requests[] = array(
            'method' => 'batchEmbedContents',
            'model' => $model,
            'payload' => $payload,
        );

        if (empty($this->queuedResponses)) {
            throw new \RuntimeException('No queued fake Gemini response');
        }

        return array_shift($this->queuedResponses);
    }

    public function uploadFile($path, array $options = array())
    {
        $this->requests[] = array(
            'method' => 'uploadFile',
            'path' => $path,
            'options' => $options,
        );

        if (empty($this->queuedResponses)) {
            throw new \RuntimeException('No queued fake Gemini response');
        }

        return array_shift($this->queuedResponses);
    }
}
