<?php

declare (strict_types=1);
namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Checkout\Payment;

/**
 * Resolves a handler ID to a payment processor instance.
 */
final class PaymentHandlerResolver
{
    /**
     * @var PaymentHandlerInterface[]
     */
    private array $handlers;
    /**
     * @param PaymentHandlerInterface[] $handlers
     */
    public function __construct(array $handlers)
    {
        $this->handlers = $handlers;
    }
    /**
     * Resolve a handler ID to a payment processor.
     */
    public function resolve(string $handler_id): ?PaymentHandlerInterface
    {
        foreach ($this->handlers as $handler) {
            if ($handler->supports($handler_id)) {
                return $handler;
            }
        }
        return null;
    }
}
