<?php

namespace App\Services\Payment;

use App\Services\Payment\Contracts\PaymentDriver;
use RuntimeException;

class PaymentManager
{
    public function driver(?string $name = null): PaymentDriver
    {
        $name ??= config('payments.default_driver', 'manual');
        $config = config("payments.drivers.{$name}");
        $class = $config['class'] ?? null;

        if (! $class || ! class_exists($class)) {
            throw new RuntimeException("El driver de pagos [{$name}] no está disponible.");
        }

        return app($class, ['config' => $config]);
    }
}
