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

use boru\ai\Asset\Attachment;
use boru\ai\Asset\ProviderAssetBinding;
use boru\ai\Provider\Gemini\GeminiMapper;
use boru\ai\Schema\Request;
use PHPUnit\Framework\TestCase;

class GeminiAttachmentMappingTest extends TestCase
{
    public function testMapsFileAttachmentUsingProviderUriBinding()
    {
        $request = new Request();
        $request->model('gemini-2.5-pro')->addMessage('Summarize the attached file.');

        $attachment = new Attachment();
        $attachment->assetId('asset_1')->kind('file');
        $request->addAttachment($attachment);

        $binding = new ProviderAssetBinding();
        $binding->assetId('asset_1')->provider('gemini')->providerUri('https://example.test/files/abc')->mimeType('application/pdf');
        $request->addAssetBinding($binding);

        $mapper = new GeminiMapper();
        $payload = $mapper->mapRequest($request);

        $this->assertCount(2, $payload['contents']);
        $this->assertSame('user', $payload['contents'][1]['role']);
        $this->assertSame('application/pdf', $payload['contents'][1]['parts'][0]['fileData']['mimeType']);
        $this->assertSame('https://example.test/files/abc', $payload['contents'][1]['parts'][0]['fileData']['fileUri']);
    }

    public function testMapsImageAttachmentUsingProviderUriBinding()
    {
        $request = new Request();
        $request->model('gemini-2.5-pro')->addMessage('Describe the image.');

        $attachment = new Attachment();
        $attachment->assetId('asset_2')->kind('image')->detail('high');
        $request->addAttachment($attachment);

        $binding = new ProviderAssetBinding();
        $binding->assetId('asset_2')->provider('gemini')->providerUri('https://example.test/files/image')->mimeType('image/png');
        $request->addAssetBinding($binding);

        $mapper = new GeminiMapper();
        $payload = $mapper->mapRequest($request);

        $this->assertCount(2, $payload['contents']);
        $this->assertSame('user', $payload['contents'][1]['role']);
        $this->assertSame('image/png', $payload['contents'][1]['parts'][0]['fileData']['mimeType']);
        $this->assertSame('https://example.test/files/image', $payload['contents'][1]['parts'][0]['fileData']['fileUri']);
    }
}
