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

use boru\ai\Asset\Attachment;
use boru\ai\Asset\ProviderAssetBinding;
use boru\ai\Provider\OpenAI\OpenAIMapper;
use boru\ai\Schema\Request;
use PHPUnit\Framework\TestCase;

class OpenAIAttachmentMappingTest extends TestCase
{
    public function testMapsFileAttachmentUsingProviderAssetBinding()
    {
        $request = new Request();
        $request->model('gpt-5.1')->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('openai')->providerAssetId('file_abc');
        $request->addAssetBinding($binding);

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

        $this->assertCount(2, $payload['input']);
        $this->assertSame('input_file', $payload['input'][1]['content'][0]['type']);
        $this->assertSame('file_abc', $payload['input'][1]['content'][0]['file_id']);
    }

    public function testMapsImageAttachmentUsingProviderAssetBindingAndDetail()
    {
        $request = new Request();
        $request->model('gpt-5.1')->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('openai')->providerAssetId('file_img_123');
        $request->addAssetBinding($binding);

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

        $this->assertCount(2, $payload['input']);
        $this->assertSame('input_image', $payload['input'][1]['content'][0]['type']);
        $this->assertSame('file_img_123', $payload['input'][1]['content'][0]['file_id']);
        $this->assertSame('high', $payload['input'][1]['content'][0]['detail']);
    }
}
