<?php

/*
|--------------------------------------------------------------------------
| OwnStore - Build your own online store
| Author: TakfeDev (MKJUEL)
| All Rights Reserved
|--------------------------------------------------------------------------
*/

namespace App\Services\Payments;

use App\Models\PaymentGateway;
use App\Services\Payments\Gateways\StripeGateway;
use App\Services\Payments\Gateways\PayPalGateway;
use App\Services\Payments\Gateways\SSLCommerzGateway;
// use App\Services\Payments\Gateways\BkashGateway;
use App\Services\Payments\Gateways\RazorpayGateway;
use App\Services\Payments\Gateways\PaystackGateway;
use App\Services\Payments\Gateways\FlutterwaveGateway;
// use App\Services\Payments\Gateways\YooMoneyGateway;
// use App\Services\Payments\Gateways\AlipayGateway;
use App\Services\Payments\Gateways\ManualGateway; 
use Exception;

class PaymentManager
{
    public function build(string $code)
    {
        $gateway = PaymentGateway::where('code', $code)->where('is_active', true)->first();

        if (!$gateway) {
            throw new Exception("Payment gateway [{$code}] is not active or not configured.");
        }

        return match ($code) {
            'stripe'      => new StripeGateway($gateway, $gateway->mode),
            'paypal'      => new PayPalGateway($gateway, $gateway->mode),
            'razorpay'    => new RazorpayGateway($gateway, $gateway->mode),
            'paystack'    => new PaystackGateway($gateway, $gateway->mode),
            'flutterwave' => new FlutterwaveGateway($gateway, $gateway->mode),
            // 'yoomoney'    => new YooMoneyGateway($gateway, $gateway->mode),
            // 'alipay'      => new AlipayGateway($gateway, $gateway->mode),
            'sslcommerz'  => new SSLCommerzGateway($gateway, $gateway->mode),
            // 'bkash'       => new BkashGateway($gateway, $gateway->mode),
            'manual'      => new ManualGateway($gateway, $gateway->mode),
            default       => throw new Exception("Plugin for [{$code}] not implemented."),
        };
    }
}