<?php

namespace App\Http\Controllers\Student;

use App\Http\Controllers\Controller;
use App\Models\Payment;
use App\Models\Plan;
use App\Models\Setting;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class SubscriptionController extends Controller
{
    /**
     * Display subscription plans and user's subscription status.
     */
    public function index()
    {
        $user = Auth::user();
        $plans = Plan::all();
        $activeSubscription = $user->activeSubscription;
        $payments = Payment::where('user_id', $user->id)
            ->with('plan')
            ->latest()
            ->take(10)
            ->get();

        return view('student.subscriptions.index', compact('plans', 'user', 'activeSubscription', 'payments'));
    }

    /**
     * Display plan selection with payment method options.
     */
    public function selectPlan(Plan $plan)
    {
        $stripeEnabled = Setting::isEnabled('stripe_enabled');
        $paypalEnabled = Setting::isEnabled('paypal_enabled');

        return view('student.subscriptions.select-method', compact('plan', 'stripeEnabled', 'paypalEnabled'));
    }
}
