<?php

/*
 * This file is part of the VitiCore 2.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Manager;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Form\Admin\Payment\PaymentMethodInterface;

final class PaymentMethodManager
{
    /** @var list<PaymentMethodInterface> */
    private array $methods = [];

    public function addMethod(PaymentMethodInterface $method): void
    {
        $this->methods[] = $method;
    }

    /**
     * @return class-string
     */
    public function createFormPaymentMethodManager(string $method): string
    {
        foreach ($this->methods as $item) {
            if ($item->getMethod() === $method) {
                return $item->getFormType();
            }
        }

        throw new \RuntimeException('Pas de paiement configuré pour ce site');
    }
}
