<?php

namespace Tests\Unit;

use App\VehicleSpec\Services\CapSectorMapper;
use Tests\TestCase;

class CapSectorMapperTest extends TestCase
{
    private CapSectorMapper $mapper;

    protected function setUp(): void
    {
        parent::setUp();
        $this->mapper = new CapSectorMapper();
    }

    public function testReturnsEmptyArrayForNull(): void
    {
        $this->assertSame([], $this->mapper->candidates(null));
    }

    public function testReturnsEmptyArrayForEmptyString(): void
    {
        $this->assertSame([], $this->mapper->candidates(''));
    }

    public function testReturnsEmptyArrayForWhitespaceOnly(): void
    {
        $this->assertSame([], $this->mapper->candidates('   '));
    }

    public function testSingleTokenIsCapitalised(): void
    {
        $this->assertSame(['Convertible'], $this->mapper->candidates('convertible'));
    }

    public function testMultiTokenReturnsAllTokensCapitalised(): void
    {
        $this->assertSame(
            ['Convertible', 'Small'],
            $this->mapper->candidates('Convertible Small')
        );
    }

    public function testPrestigePrefixedSectorSurfacesBodyTypeAsSecondCandidate(): void
    {
        $this->assertSame(
            ['Prestige', 'Convertible', 'Small'],
            $this->mapper->candidates('Prestige Convertible Small')
        );
    }

    public function testCollapsesInternalWhitespace(): void
    {
        $this->assertSame(
            ['Convertible', 'Small'],
            $this->mapper->candidates('  Convertible    Small  ')
        );
    }

    public function testUncategorisedIsAllowedThroughAsCandidate(): void
    {
        $this->assertSame(['Uncategorised'], $this->mapper->candidates('Uncategorised'));
    }

    public function testBareSizeSectorReturnsSizeAsSoleCandidate(): void
    {
        $this->assertSame(['Small'], $this->mapper->candidates('Small'));
    }

    public function testMixedCaseInputIsNormalised(): void
    {
        $this->assertSame(
            ['Convertible', 'Small'],
            $this->mapper->candidates('CONVERTIBLE small')
        );
    }

    public function testFourByFourPreservedAsToken(): void
    {
        $this->assertSame(
            ['4x4', 'Medium'],
            $this->mapper->candidates('4x4 Medium')
        );
    }
}
