<?php

namespace App\Tests\Service\Search;

use App\Service\Search\Client;
use Meilisearch\Client as MeilisearchClient;
use Meilisearch\Endpoints\Indexes;
use Meilisearch\Search\SearchResult;
use PHPUnit\Framework\TestCase;

class ClientTest extends TestCase
{
    public function testStatus(): void
    {
        $msClient = $this->createStub(MeilisearchClient::class);
        $msClient->method('health')->willReturn(['status' => 'available']);

        $client = new Client($msClient);
        $this->assertTrue($client->status());
    }

    public function testSearch(): void
    {
        $msClient = $this->createStub(MeilisearchClient::class);
        $indexMock = $this->createStub(Indexes::class);
        
        $msClient->method('index')->willReturn($indexMock);
        
        // Mock SearchResult
        $searchResult = $this->createStub(SearchResult::class);
        $searchResult->method('toArray')->willReturn(['hits' => []]);
        $indexMock->method('search')->willReturn($searchResult);

        $client = new Client($msClient);
        $result = $client->search('product', 'query');
        
        $this->assertIsArray($result);
    }
}
