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

use boru\ai\Config\Config;
use PHPUnit\Framework\TestCase;

class ConfigTest extends TestCase
{
    public function testSetAndGetNestedConfigValues()
    {
        $config = new Config();
        $config->set('providers.openai.api_key', 'abc123');
        $config->set('defaults.model', 'gpt-5.1');

        $this->assertSame('abc123', $config->get('providers.openai.api_key'));
        $this->assertSame('gpt-5.1', $config->get('defaults.model'));
    }

    public function testProviderHelperMergesConfig()
    {
        $config = new Config();
        $config->provider('openai', array('api_key' => 'a'));
        $config->provider('openai', array('timeout' => 60));

        $providerConfig = $config->provider('openai');
        $this->assertSame('a', $providerConfig['api_key']);
        $this->assertSame(60, $providerConfig['timeout']);
    }

    public function testMergeCombinesNestedArrays()
    {
        $config = new Config(array(
            'defaults' => array(
                'provider' => 'openai',
            ),
        ));

        $config->merge(array(
            'defaults' => array(
                'model' => 'gpt-5.1',
            ),
        ));

        $this->assertSame('openai', $config->get('defaults.provider'));
        $this->assertSame('gpt-5.1', $config->get('defaults.model'));
    }

    public function testDbHelperMergesConfig()
    {
        $config = new Config();
        $config->db(array('dbhost' => '127.0.0.1'));
        $config->db(array('dbname' => 'ai_test'));

        $dbConfig = $config->db();
        $this->assertSame('127.0.0.1', $dbConfig['dbhost']);
        $this->assertSame('ai_test', $dbConfig['dbname']);
    }
}
