<?php

namespace Tests\Unit\Framework;

use Openguru\OpenCartFramework\QueryBuilder\QueryResult;
use PHPUnit\Framework\TestCase;

class QueryResultTest extends TestCase
{
    public function testConstructorSetsProperties(): void
    {
        $row = ['id' => 1, 'name' => 'Test'];
        $rows = [['id' => 1], ['id' => 2]];
        $numRows = 2;

        $result = new QueryResult($row, $rows, $numRows);

        $this->assertEquals($row, $result->getRow());
        $this->assertEquals($rows, $result->getRows());
        $this->assertEquals($numRows, $result->getNumRows());
    }

    public function testGetRowReturnsSingleRow(): void
    {
        $row = ['id' => 1, 'name' => 'Test'];
        $result = new QueryResult($row, [], 0);

        $this->assertEquals($row, $result->getRow());
    }

    public function testGetRowsReturnsAllRows(): void
    {
        $rows = [
            ['id' => 1, 'name' => 'Test1'],
            ['id' => 2, 'name' => 'Test2'],
        ];
        $result = new QueryResult(null, $rows, 2);

        $this->assertEquals($rows, $result->getRows());
    }

    public function testGetNumRowsReturnsCount(): void
    {
        $result = new QueryResult(null, [], 5);

        $this->assertEquals(5, $result->getNumRows());
    }

    public function testCanHandleNullRow(): void
    {
        $result = new QueryResult(null, [], 0);

        $this->assertNull($result->getRow());
    }

    public function testCanHandleEmptyRows(): void
    {
        $result = new QueryResult(null, [], 0);

        $this->assertEquals([], $result->getRows());
        $this->assertEquals(0, $result->getNumRows());
    }
}

