<?php

declare(strict_types=1);

namespace App\Tests\Unit\Administration\Application\Service\Import;

use App\Administration\Application\Service\Import\MultiValueParser;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class MultiValueParserTest extends TestCase
{
    private MultiValueParser $parser;

    protected function setUp(): void
    {
        $this->parser = new MultiValueParser();
    }

    #[Test]
    public function parseSingleValue(): void
    {
        $result = $this->parser->parse('Mathématiques');

        self::assertSame(['Mathématiques'], $result);
    }

    #[Test]
    public function parseMultipleValues(): void
    {
        $result = $this->parser->parse('Mathématiques, Physique');

        self::assertSame(['Mathématiques', 'Physique'], $result);
    }

    #[Test]
    public function parseTrimsWhitespace(): void
    {
        $result = $this->parser->parse('  Mathématiques ,  Physique  , Chimie  ');

        self::assertSame(['Mathématiques', 'Physique', 'Chimie'], $result);
    }

    #[Test]
    public function parseEmptyStringReturnsEmptyArray(): void
    {
        $result = $this->parser->parse('');

        self::assertSame([], $result);
    }

    #[Test]
    public function parseOnlyWhitespaceReturnsEmptyArray(): void
    {
        $result = $this->parser->parse('   ');

        self::assertSame([], $result);
    }

    #[Test]
    public function parseWithCustomSeparator(): void
    {
        $result = $this->parser->parse('6A;6B;5A', ';');

        self::assertSame(['6A', '6B', '5A'], $result);
    }

    #[Test]
    public function parseFiltersOutEmptyValues(): void
    {
        $result = $this->parser->parse('Mathématiques,,Physique,');

        self::assertSame(['Mathématiques', 'Physique'], $result);
    }

    #[Test]
    public function parseWithClassNames(): void
    {
        $result = $this->parser->parse('6A, 6B, 5A');

        self::assertSame(['6A', '6B', '5A'], $result);
    }
}
