<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\Form\Filter;

use Doctrine\ORM\QueryBuilder;
use Ferienpass\AdminBundle\Form\Filter\AbstractFilterType;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Form\FormInterface;
use Symfony\Contracts\Translation\TranslatableInterface;

final class AbstractFilterTypeTest extends TestCase
{
    private AbstractFilterType $filter;

    protected function setUp(): void
    {
        $this->filter = new class extends AbstractFilterType {
            public function apply(QueryBuilder $qb, FormInterface $form): void {}

            protected function getHumanReadableValue(FormInterface $form): string|TranslatableInterface|null
            {
                return null;
            }
        };
    }

    public function testSupportsAllViewsByDefault(): void
    {
        self::assertTrue($this->filter->supports('any_view'));
        self::assertTrue($this->filter->supports('another_view'));
    }

    public function testSupportsOnlyConfiguredViews(): void
    {
        $this->filter->setViews(['view_a', 'view_b']);

        self::assertTrue($this->filter->supports('view_a'));
        self::assertTrue($this->filter->supports('view_b'));
        self::assertFalse($this->filter->supports('view_c'));
    }

    public function testGetSectionReturnsDefaultWhenNotSet(): void
    {
        self::assertSame('default', $this->filter->getSection());
    }

    public function testSetAndGetSection(): void
    {
        $this->filter->setSection('my_section');
        self::assertSame('my_section', $this->filter->getSection());
    }

    public function testSetSectionToNullReturnsDefault(): void
    {
        $this->filter->setSection('my_section');
        $this->filter->setSection(null);
        self::assertSame('default', $this->filter->getSection());
    }

    public function testGetPriorityDefaultsToZero(): void
    {
        self::assertSame(0, $this->filter->getPriority());
    }

    public function testSetAndGetPriority(): void
    {
        $this->filter->setPriority(42);
        self::assertSame(42, $this->filter->getPriority());
    }

    public function testShallDisplayReturnsTrueByDefault(): void
    {
        self::assertTrue($this->filter->shallDisplay());
        self::assertTrue($this->filter->shallDisplay('some_view'));
    }
}
