<?php
namespace Tests\Unit\admin\Controllers;

use PHPUnit\Framework\TestCase;
use admin\Controllers\DictionariesController;
use Domain\Dictionaries\DictionariesRepository;
use Domain\Languages\LanguagesRepository;

class DictionariesControllerTest extends TestCase
{
    private $mockRepository;
    private $mockLanguagesRepository;
    private $controller;

    protected function setUp(): void
    {
        $this->mockRepository = $this->createMock(DictionariesRepository::class);
        $this->mockLanguagesRepository = $this->createMock(LanguagesRepository::class);
        $this->controller = new DictionariesController($this->mockRepository, $this->mockLanguagesRepository);
    }

    public function testConstructorAcceptsRepository(): void
    {
        $controller = new DictionariesController($this->mockRepository, $this->mockLanguagesRepository);
        $this->assertInstanceOf(DictionariesController::class, $controller);
    }

    public function testHasListMethod(): void
    {
        $this->assertTrue(method_exists($this->controller, 'list'));
    }

    public function testHasEditMethod(): void
    {
        $this->assertTrue(method_exists($this->controller, 'edit'));
    }

    public function testHasSaveMethod(): void
    {
        $this->assertTrue(method_exists($this->controller, 'save'));
    }

    public function testHasDeleteMethod(): void
    {
        $this->assertTrue(method_exists($this->controller, 'delete'));
    }

    public function testActionMethodReturnTypes(): void
    {
        $reflection = new \ReflectionClass($this->controller);

        $this->assertEquals('string', (string)$reflection->getMethod('list')->getReturnType());
        $this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType());
        $this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType());
        $this->assertEquals('void', (string)$reflection->getMethod('delete')->getReturnType());
    }

    public function testConstructorRequiresDictionariesRepository(): void
    {
        $reflection = new \ReflectionClass(DictionariesController::class);
        $constructor = $reflection->getConstructor();
        $params = $constructor->getParameters();

        $this->assertCount(2, $params);
        $this->assertEquals('Domain\Dictionaries\DictionariesRepository', $params[0]->getType()->getName());
        $this->assertEquals('Domain\Languages\LanguagesRepository', $params[1]->getType()->getName());
    }
}
