<?php

namespace App\Services;

use App\Models\Station;

class StationTaggingService
{
    /** @var array<string, string> brand keyword → normalised brand name */
    private const SUPERMARKET_BRANDS = [
        'tesco' => 'Tesco',
        'asda' => 'Asda',
        'morrisons' => 'Morrisons',
        'sainsbury' => 'Sainsbury\'s',
        'aldi' => 'Aldi',
        'lidl' => 'Lidl',
        'costco' => 'Costco',
    ];

    public function tag(Station $station): void
    {
        $tradingName = strtolower($station->trading_name);
        $brandName = strtolower($station->brand_name ?? '');

        foreach (self::SUPERMARKET_BRANDS as $keyword => $normalisedBrand) {
            if (str_contains($tradingName, $keyword) || str_contains($brandName, $keyword)) {
                $station->is_supermarket = true;
                $station->brand_name = $normalisedBrand;

                return;
            }
        }
    }
}
