<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use App\Models\Gateway;
use Illuminate\Http\Request;

class PayController extends Controller
{
    public function index(Request $request)
    {
        $data['title'] = 'Fund Account';

        $paystack    = Gateway::where('gateway_name', 'paystack')->where('status', 1)->first();
        $flutterwave = Gateway::where('gateway_name', 'flutterwave')->where('status', 1)->first();
        $bank        = Gateway::where('gateway_name', 'bank')->where('status', 1)->first();

        $data['paystackPublicKey']    = $paystack ? ($paystack->gateway_parameters->paystack_public_key ?? null) : null;
        $data['paystackCurrency']     = $paystack ? ($paystack->gateway_parameters->gateway_currency ?? 'NGN') : 'NGN';
        $data['paystackEnabled']      = (bool) $paystack;

        $data['flutterwavePublicKey'] = $flutterwave ? ($flutterwave->gateway_parameters->public_key ?? null) : null;
        $data['flutterwaveCurrency']  = $flutterwave ? ($flutterwave->gateway_parameters->gateway_currency ?? 'NGN') : 'NGN';
        $data['flutterwaveEnabled']   = (bool) $flutterwave;

        $data['bankEnabled']          = (bool) $bank;
        $data['bankCurrency']         = $bank ? ($bank->gateway_parameters->gateway_currency ?? 'NGN') : 'NGN';

        return view('frontend.user.payment.index', $data);
    }
}
