<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\ApplicationSystem;

use Ferienpass\AdminBundle\ApplicationSystem\ParticipantListDto;
use Ferienpass\CoreBundle\Entity\Offer\OfferInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

final class ParticipantListDtoTest extends TestCase
{
    private function makeDto(): ParticipantListDto
    {
        $dispatcher = $this->createMock(EventDispatcherInterface::class);
        $dispatcher->method('dispatch')->willReturnArgument(0);

        return new ParticipantListDto($dispatcher);
    }

    public function testAdminViewColumnsReturnsArrayForNormalRequest(): void
    {
        $dto = $this->makeDto();
        $offer = $this->createMock(OfferInterface::class);
        $request = new Request();

        $columns = $dto->adminViewColumns($offer, $request);

        self::assertIsArray($columns);
        self::assertArrayHasKey('name', $columns);
        self::assertArrayHasKey('status', $columns);
        self::assertArrayHasKey('consents', $columns);
    }

    public function testAdminViewColumnsForNormalRequestIncludesContactColumns(): void
    {
        $dto = $this->makeDto();
        $offer = $this->createMock(OfferInterface::class);
        $request = new Request();

        $columns = $dto->adminViewColumns($offer, $request);

        self::assertArrayHasKey('email', $columns);
        self::assertArrayHasKey('mobile', $columns);
        self::assertArrayHasKey('phone', $columns);
    }

    public function testAdminViewColumnsForSlideoverRequestExcludesContactColumns(): void
    {
        $dto = $this->makeDto();
        $offer = $this->createMock(OfferInterface::class);
        $request = new Request();
        $request->headers->set('turbo-frame', 'slideover');

        $columns = $dto->adminViewColumns($offer, $request);

        self::assertIsArray($columns);
        self::assertArrayNotHasKey('email', $columns);
        self::assertArrayNotHasKey('mobile', $columns);
        self::assertArrayNotHasKey('phone', $columns);
    }

    public function testAdminViewColumnsForSlideoverRequestHasRequiredKeys(): void
    {
        $dto = $this->makeDto();
        $offer = $this->createMock(OfferInterface::class);
        $request = new Request();
        $request->headers->set('turbo-frame', 'slideover');

        $columns = $dto->adminViewColumns($offer, $request);

        self::assertArrayHasKey('name', $columns);
        self::assertArrayHasKey('status', $columns);
        self::assertArrayHasKey('consents', $columns);
    }
}
