<?php

use App\Models\Station;
use App\Services\StationTaggingService;

beforeEach(function (): void {
    $this->service = new StationTaggingService;
});

it('marks tesco station as supermarket and normalises brand', function (): void {
    $station = new Station([
        'trading_name' => 'TESCO EXTRA',
        'is_supermarket' => false,
    ]);

    $this->service->tag($station);

    expect($station->is_supermarket)->toBeTrue()
        ->and($station->brand_name)->toBe('Tesco');
});

it('marks asda station as supermarket', function (): void {
    $station = new Station([
        'trading_name' => 'Asda Petrol Station',
        'is_supermarket' => false,
    ]);

    $this->service->tag($station);

    expect($station->is_supermarket)->toBeTrue()
        ->and($station->brand_name)->toBe('Asda');
});

it('does not mark independent station as supermarket', function (): void {
    $station = new Station([
        'trading_name' => 'Village Garage',
        'is_supermarket' => false,
    ]);

    $this->service->tag($station);

    expect($station->is_supermarket)->toBeFalse();
});

it('handles case insensitive matching', function (): void {
    $station = new Station([
        'trading_name' => 'morrisons petrol',
        'is_supermarket' => false,
    ]);

    $this->service->tag($station);

    expect($station->is_supermarket)->toBeTrue()
        ->and($station->brand_name)->toBe('Morrisons');
});

it('marks station as supermarket when brand_name matches even if trading_name does not', function (): void {
    $station = new Station([
        'trading_name' => 'PETERBOROUGH EXTRA - PETROL FILLING STATION',
        'brand_name' => 'TESCO',
        'is_supermarket' => false,
    ]);

    $this->service->tag($station);

    expect($station->is_supermarket)->toBeTrue()
        ->and($station->brand_name)->toBe('Tesco');
});

it('does not overwrite brand_name for non-supermarket stations', function (): void {
    $station = new Station([
        'trading_name' => 'Shell Garage',
        'brand_name' => 'Shell',
        'is_supermarket' => false,
    ]);

    $this->service->tag($station);

    expect($station->is_supermarket)->toBeFalse()
        ->and($station->brand_name)->toBe('Shell');
});
