<?php

namespace Tests\Unit\Support;

use App\Facades\Settings;
use App\Support\FeedDescription;
use Mtc\MercuryDataModels\Vehicle;
use Tests\TestCase;

class FeedDescriptionTest extends TestCase
{
    private function vehicle(?string $description, ?string $feedDescription): Vehicle
    {
        $vehicle = new Vehicle();
        $vehicle->description = $description;
        $vehicle->description_for_feeds = $feedDescription;

        return $vehicle;
    }

    public function testReturnsStandardDescriptionWhenSettingDisabled(): void
    {
        Settings::shouldReceive('get')
            ->with('sales-channels-feed-description-enabled', false)
            ->andReturn(false);

        $result = FeedDescription::for($this->vehicle('Standard', 'Feed'));

        $this->assertSame('Standard', $result);
    }

    public function testReturnsFeedDescriptionWhenSettingEnabled(): void
    {
        Settings::shouldReceive('get')
            ->with('sales-channels-feed-description-enabled', false)
            ->andReturn(true);

        $result = FeedDescription::for($this->vehicle('Standard', 'Feed'));

        $this->assertSame('Feed', $result);
    }

    public function testReturnsEmptyFeedDescriptionWhenSettingEnabledAndFeedFieldBlank(): void
    {
        Settings::shouldReceive('get')
            ->with('sales-channels-feed-description-enabled', false)
            ->andReturn(true);

        $result = FeedDescription::for($this->vehicle('Standard', null));

        $this->assertNull($result);
    }
}
