<?php

declare(strict_types=1);

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

use App\Administration\Application\Service\Import\ImportFormatDetector;
use App\Administration\Domain\Model\Import\KnownImportFormat;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class ImportFormatDetectorTest extends TestCase
{
    private ImportFormatDetector $detector;

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

    #[Test]
    public function detectsPronoteFormat(): void
    {
        $columns = ['Élèves', 'Encouragement/Valorisation', 'Né(e) le', 'Sexe', 'Adresse E-mail', 'Entrée', 'Sortie', 'Classe de rattachement'];

        $format = $this->detector->detecter($columns);

        self::assertSame(KnownImportFormat::PRONOTE, $format);
    }

    #[Test]
    public function detectsEcoleDirecteFormat(): void
    {
        $columns = ['NOM', 'PRENOM', 'CLASSE', 'DATE_NAISSANCE', 'SEXE'];

        $format = $this->detector->detecter($columns);

        self::assertSame(KnownImportFormat::ECOLE_DIRECTE, $format);
    }

    #[Test]
    public function detectsCustomFormatForUnknownColumns(): void
    {
        $columns = ['Nom', 'Prénom', 'Classe', 'Email'];

        $format = $this->detector->detecter($columns);

        self::assertSame(KnownImportFormat::CUSTOM, $format);
    }

    #[Test]
    public function detectsPronoteWithPartialMatch(): void
    {
        $columns = ['Élèves', 'Né(e) le', 'Sexe', 'Autre colonne'];

        $format = $this->detector->detecter($columns);

        self::assertSame(KnownImportFormat::PRONOTE, $format);
    }

    #[Test]
    public function detectsEcoleDirecteWithCaseVariations(): void
    {
        $columns = ['nom', 'prenom', 'classe', 'date_naissance'];

        $format = $this->detector->detecter($columns);

        self::assertSame(KnownImportFormat::ECOLE_DIRECTE, $format);
    }
}
