<?php

declare(strict_types=1);

namespace App\Services\Billing\Gateway;

use App\Models\PaymentGateway;
use RuntimeException;

/** Резолвер активного шлюза и его драйвера. */
final class PaymentGatewayManager
{
    public function activeGateway(): ?PaymentGateway
    {
        return PaymentGateway::where('is_active', true)->orderBy('sort_order')->first();
    }

    public function driverFor(PaymentGateway $gateway): PaymentGatewayDriver
    {
        return match ($gateway->driver) {
            'yookassa' => new YooKassaDriver,
            default => throw new RuntimeException('Неизвестный драйвер шлюза: '.$gateway->driver),
        };
    }
}
