<?php

namespace Tests\Tenant;

use Mtc\MercuryDataModels\Filters\VehicleAttributeValueMaxFilter;
use Mtc\MercuryDataModels\Filters\VehicleAttributeValueMinFilter;
use Mtc\MercuryDataModels\VehicleAttribute;
use Tests\TenantTestCase;

class VehicleAttributeFilterUnitTest extends TenantTestCase
{
    private function createNumericAttribute(?string $unit = null): VehicleAttribute
    {
        return VehicleAttribute::forceCreate([
            'name' => 'Length',
            'slug' => 'length',
            'type' => 'integer',
            'model' => 'vehicle',
            'sortable' => 0,
            'filterable' => 1,
            'count' => 1,
            'validation' => '[]',
            'data' => '[]',
            'unit' => $unit,
        ]);
    }

    public function testMinFilterLabelUsesUnitAsTightSuffixWhenSet(): void
    {
        $this->createNumericAttribute('m');

        $filter = new VehicleAttributeValueMinFilter('length_min');

        $this->assertEquals('From 2m', $filter->getSelectionName(2));
    }

    public function testMinFilterLabelFallsBackToAttributeNameWhenUnitIsNull(): void
    {
        $this->createNumericAttribute(null);

        $filter = new VehicleAttributeValueMinFilter('length_min');

        $this->assertEquals('From 2 Length', $filter->getSelectionName(2));
    }

    public function testMaxFilterLabelUsesUnitAsTightSuffixWhenSet(): void
    {
        $this->createNumericAttribute('m');

        $filter = new VehicleAttributeValueMaxFilter('length_max');

        $this->assertEquals('Up To 5m', $filter->getSelectionName(5));
    }

    public function testMaxFilterLabelFallsBackToAttributeNameWhenUnitIsNull(): void
    {
        $this->createNumericAttribute(null);

        $filter = new VehicleAttributeValueMaxFilter('length_max');

        $this->assertEquals('Up To 5 Length', $filter->getSelectionName(5));
    }
}
