<?php

namespace App\VehicleSpec\Services;

class CapSectorMapper
{
    /**
     * Return the candidate body-type tokens from a CAP SectorDescription,
     * in the order they should be tried against the body_styles taxonomy.
     *
     */
    public function candidates(?string $sector): array
    {
        if (empty($sector)) {
            return [];
        }

        $tokens = preg_split('/\s+/', trim($sector)) ?: [];

        return array_values(array_filter(
            array_map(fn ($token) => ucfirst(strtolower($token)), $tokens),
            fn ($token) => $token !== ''
        ));
    }
}
