<?php

namespace App\Http\Controllers;

use App\Models\SiteSetting;
use App\Models\SubscriptionPlan;
use App\Services\Payments\PaymentManagerService;
use Illuminate\Http\Request;
use Illuminate\View\View;

class PricingController extends Controller
{
    public function __invoke(Request $request, PaymentManagerService $payments): View
    {
        $paymentSettings = SiteSetting::paymentSettings();
        $paymentModeEnabled = SiteSetting::paymentModeEnabled();
        $activeGateway = $paymentModeEnabled ? $payments->activeConfiguredGateway() : null;

        return view('pricing', [
            'plans' => SubscriptionPlan::query()
                ->active()
                ->orderByDesc('is_recommended')
                ->orderBy('sort_order')
                ->orderBy('price')
                ->get(),
            'paymentSettings' => $paymentSettings,
            'paymentModeEnabled' => $paymentModeEnabled,
            'activeGateway' => $activeGateway,
        ]);
    }
}
