<?php
declare(strict_types=1);

namespace App\Modules\Shipments;

final class ShipmentTrackingRegistry
{
    /** @var ShipmentTrackingInterface[] */
    private readonly array $services;

    /**
     * @param ShipmentTrackingInterface[] $services
     */
    public function __construct(array $services)
    {
        $this->services = $services;
    }

    public function getForProvider(string $provider): ?ShipmentTrackingInterface
    {
        foreach ($this->services as $service) {
            if ($service->supports($provider)) {
                return $service;
            }
        }

        return null;
    }
}
