<?php

namespace App\Services;

use App\Exceptions\RoutingMismatchException;
use App\Models\Feed;
use App\Models\PlatformChannel;
use Illuminate\Support\Collection;

class RoutingValidationService
{
    /**
     * @param  Collection<int, PlatformChannel>  $channels
     *
     * @throws RoutingMismatchException
     */
    public function validateLanguageCompatibility(Feed $feed, Collection $channels): void
    {
        if (! $feed->language) {
            return;
        }

        foreach ($channels as $channel) {
            if (! $channel->language) {
                continue;
            }

            if ($feed->language !== $channel->language) {
                throw new RoutingMismatchException($feed, $channel);
            }
        }
    }
}
