<?php

namespace MintyPHP\Tests\Service\Directory;

use MintyPHP\Service\Directory\DirectorySettingsGateway;
use MintyPHP\Service\Settings\SettingsAppGateway;
use MintyPHP\Service\Settings\SettingsDefaultsGateway;
use PHPUnit\Framework\TestCase;

class DirectorySettingsGatewayTest extends TestCase
{
    public function testSetDefaultTenantIdDelegatesToSettingsDefaultsGateway(): void
    {
        $defaults = $this->createMock(SettingsDefaultsGateway::class);
        $defaults->expects($this->once())
            ->method('setDefaultTenantId')
            ->with(42);

        $app = $this->createMock(SettingsAppGateway::class);

        $gateway = new DirectorySettingsGateway($defaults, $app);
        $gateway->setDefaultTenantId(42);
    }

    public function testSetDefaultTenantIdAcceptsNull(): void
    {
        $defaults = $this->createMock(SettingsDefaultsGateway::class);
        $defaults->expects($this->once())
            ->method('setDefaultTenantId')
            ->with(null);

        $app = $this->createMock(SettingsAppGateway::class);

        $gateway = new DirectorySettingsGateway($defaults, $app);
        $gateway->setDefaultTenantId(null);
    }

    public function testSetDefaultDepartmentIdDelegatesToSettingsDefaultsGateway(): void
    {
        $defaults = $this->createMock(SettingsDefaultsGateway::class);
        $defaults->expects($this->once())
            ->method('setDefaultDepartmentId')
            ->with(7);

        $app = $this->createMock(SettingsAppGateway::class);

        $gateway = new DirectorySettingsGateway($defaults, $app);
        $gateway->setDefaultDepartmentId(7);
    }

    public function testSetDefaultDepartmentIdAcceptsNull(): void
    {
        $defaults = $this->createMock(SettingsDefaultsGateway::class);
        $defaults->expects($this->once())
            ->method('setDefaultDepartmentId')
            ->with(null);

        $app = $this->createMock(SettingsAppGateway::class);

        $gateway = new DirectorySettingsGateway($defaults, $app);
        $gateway->setDefaultDepartmentId(null);
    }

    public function testSetDefaultRoleIdDelegatesToSettingsDefaultsGateway(): void
    {
        $defaults = $this->createMock(SettingsDefaultsGateway::class);
        $defaults->expects($this->once())
            ->method('setDefaultRoleId')
            ->with(3);

        $app = $this->createMock(SettingsAppGateway::class);

        $gateway = new DirectorySettingsGateway($defaults, $app);
        $gateway->setDefaultRoleId(3);
    }

    public function testSetDefaultRoleIdAcceptsNull(): void
    {
        $defaults = $this->createMock(SettingsDefaultsGateway::class);
        $defaults->expects($this->once())
            ->method('setDefaultRoleId')
            ->with(null);

        $app = $this->createMock(SettingsAppGateway::class);

        $gateway = new DirectorySettingsGateway($defaults, $app);
        $gateway->setDefaultRoleId(null);
    }

    public function testIsAllowedThemeDelegatesToSettingsAppGateway(): void
    {
        $defaults = $this->createMock(SettingsDefaultsGateway::class);
        $app = $this->createMock(SettingsAppGateway::class);
        $app->expects($this->once())
            ->method('isAllowedTheme')
            ->with('dark')
            ->willReturn(true);

        $gateway = new DirectorySettingsGateway($defaults, $app);
        $this->assertTrue($gateway->isAllowedTheme('dark'));
    }

    public function testIsAllowedThemeReturnsFalseForUnknownTheme(): void
    {
        $defaults = $this->createMock(SettingsDefaultsGateway::class);
        $app = $this->createMock(SettingsAppGateway::class);
        $app->expects($this->once())
            ->method('isAllowedTheme')
            ->with('neon')
            ->willReturn(false);

        $gateway = new DirectorySettingsGateway($defaults, $app);
        $this->assertFalse($gateway->isAllowedTheme('neon'));
    }
}
