<?php

namespace MintyPHP\Tests\Service\Settings;

use MintyPHP\Repository\Settings\SettingRepositoryInterface;
use MintyPHP\Service\Settings\SettingsAppGateway;
use MintyPHP\Service\Settings\SettingsMetadataGateway;
use PHPUnit\Framework\TestCase;

class SettingsAppGatewayTest extends TestCase
{
    private function createGateway(SettingRepositoryInterface $settings): SettingsAppGateway
    {
        return new SettingsAppGateway(new SettingsMetadataGateway($settings));
    }

    public function testGetAppTitleReturnsNullWhenEmpty(): void
    {
        $settings = $this->createMock(SettingRepositoryInterface::class);
        $settings->expects($this->any())->method('getValue')->with('app_title')->willReturn(null);

        $gateway = $this->createGateway($settings);
        $this->assertNull($gateway->getAppTitle());
    }

    public function testGetAppTitleReturnsTrimmedValue(): void
    {
        $settings = $this->createMock(SettingRepositoryInterface::class);
        $settings->expects($this->any())->method('getValue')->with('app_title')->willReturn('  My App  ');

        $gateway = $this->createGateway($settings);
        $this->assertSame('My App', $gateway->getAppTitle());
    }

    public function testGetAppLocaleReturnsNullWhenNotSet(): void
    {
        $settings = $this->createMock(SettingRepositoryInterface::class);
        $settings->expects($this->any())->method('getValue')->with('app_locale')->willReturn(null);

        $gateway = $this->createGateway($settings);
        $this->assertNull($gateway->getAppLocale());
    }

    public function testIsRegistrationEnabledDefaultsToTrue(): void
    {
        $settings = $this->createMock(SettingRepositoryInterface::class);
        $settings->expects($this->any())->method('getValue')->with('app_registration')->willReturn(null);

        $gateway = $this->createGateway($settings);
        $this->assertTrue($gateway->isRegistrationEnabled());
    }

    public function testIsRegistrationEnabledReturnsFalseWhenDisabled(): void
    {
        $settings = $this->createMock(SettingRepositoryInterface::class);
        $settings->expects($this->any())->method('getValue')->with('app_registration')->willReturn('0');

        $gateway = $this->createGateway($settings);
        $this->assertFalse($gateway->isRegistrationEnabled());
    }
}
