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

use PHPUnit\Framework\TestCase;
use admin\Controllers\ArticlesController;
use Domain\Article\ArticleRepository;
use Domain\Languages\LanguagesRepository;
use Domain\Layouts\LayoutsRepository;
use Domain\Pages\PagesRepository;

class ArticlesControllerTest extends TestCase
{
    private $mockRepository;
    private $mockLanguagesRepository;
    private $mockLayoutsRepository;
    private $mockPagesRepository;
    private $controller;

    protected function setUp(): void
    {
        $this->mockRepository = $this->createMock(ArticleRepository::class);
        $this->mockLanguagesRepository = $this->createMock(LanguagesRepository::class);
        $this->mockLayoutsRepository = $this->createMock(LayoutsRepository::class);
        $this->mockPagesRepository = $this->createMock(PagesRepository::class);
        $this->controller = new ArticlesController(
            $this->mockRepository,
            $this->mockLanguagesRepository,
            $this->mockLayoutsRepository,
            $this->mockPagesRepository
        );
    }

    public function testCanCreateController(): void
    {
        $this->assertInstanceOf(ArticlesController::class, $this->controller);
    }

    public function testConstructorAcceptsRepository(): void
    {
        $controller = new ArticlesController(
            $this->mockRepository,
            $this->mockLanguagesRepository,
            $this->mockLayoutsRepository,
            $this->mockPagesRepository
        );
        $this->assertInstanceOf(ArticlesController::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 testHasGalleryOrderSaveMethod(): void
    {
        $this->assertTrue(method_exists($this->controller, 'galleryOrderSave'));
    }

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

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

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

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

    public function testListMethodReturnType(): void
    {
        $reflection = new \ReflectionClass($this->controller);
        $this->assertEquals('string', (string)$reflection->getMethod('list')->getReturnType());
    }

    public function testEditMethodReturnType(): void
    {
        $reflection = new \ReflectionClass($this->controller);
        $this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType());
    }

    public function testGalleryOrderSaveMethodReturnType(): void
    {
        $reflection = new \ReflectionClass($this->controller);
        $this->assertEquals('void', (string)$reflection->getMethod('galleryOrderSave')->getReturnType());
    }

    public function testImageAltChangeMethodReturnType(): void
    {
        $reflection = new \ReflectionClass($this->controller);
        $this->assertEquals('void', (string)$reflection->getMethod('imageAltChange')->getReturnType());
    }

    public function testFileNameChangeMethodReturnType(): void
    {
        $reflection = new \ReflectionClass($this->controller);
        $this->assertEquals('void', (string)$reflection->getMethod('fileNameChange')->getReturnType());
    }

    public function testImageDeleteMethodReturnType(): void
    {
        $reflection = new \ReflectionClass($this->controller);
        $this->assertEquals('void', (string)$reflection->getMethod('imageDelete')->getReturnType());
    }

    public function testFileDeleteMethodReturnType(): void
    {
        $reflection = new \ReflectionClass($this->controller);
        $this->assertEquals('void', (string)$reflection->getMethod('fileDelete')->getReturnType());
    }

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

        $this->assertCount(4, $params);
        $this->assertEquals('Domain\Article\ArticleRepository', $params[0]->getType()->getName());
        $this->assertEquals('Domain\Languages\LanguagesRepository', $params[1]->getType()->getName());
        $this->assertEquals('Domain\Layouts\LayoutsRepository', $params[2]->getType()->getName());
        $this->assertEquals('Domain\Pages\PagesRepository', $params[3]->getType()->getName());
    }
}
