<?php

namespace Tests\Unit\Framework;

use Openguru\OpenCartFramework\Config\Settings;
use Tests\TestCase;

class SettingsTest extends TestCase
{
    private $settings;

    protected function setUp(): void
    {
        $this->settings = new Settings([
            'app_name' => 'MyApp',
            'debug_mode' => true,
            'default_language' => 'en',
            'database' => [
                'host' => 'localhost',
                'port' => 3306,
            ],
        ]);
    }

    public function testGet(): void
    {
        $this->assertEquals('MyApp', $this->settings->get('app_name'));
        $this->assertTrue($this->settings->get('debug_mode'));
        $this->assertEquals('en', $this->settings->get('default_language'));
        $this->assertEquals('localhost', $this->settings->get('database.host'));
    }

    public function testGetDefault(): void
    {
        $this->assertNull($this->settings->get('non_existent_key'));
        $this->assertEquals('default_value', $this->settings->get('non_existent_key', 'default_value'));
        $this->assertEquals('default_host', $this->settings->get('database.non_existent', 'default_host'));
    }


    public function testHas(): void
    {
        $this->assertTrue($this->settings->has('app_name'));
        $this->assertTrue($this->settings->has('debug_mode'));
        $this->assertFalse($this->settings->has('non_existent_key'));
        $this->assertTrue($this->settings->has('database.host'));
        $this->assertFalse($this->settings->has('database.non_existent'));
    }

    public function testGetAll(): void
    {
        $expected = [
            'app_name' => 'MyApp',
            'debug_mode' => true,
            'default_language' => 'en',
            'database' => [
                'host' => 'localhost',
                'port' => 3306,
            ],
        ];

        $this->assertEquals($expected, $this->settings->getAll());
    }
}
