<?php

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

class SubscriptionController extends Controller
{
    public function index(Request $request): View
    {
        $user = $request->user();

        return view('subscriptions.index', [
            'activeSubscription' => $user->subscriptions()
                ->with('plan')
                ->active()
                ->latest('starts_at')
                ->first(),
            'latestSubscription' => $user->subscriptions()
                ->with('plan')
                ->latest()
                ->first(),
            'payments' => $user->payments()
                ->with(['plan', 'gateway'])
                ->latest()
                ->paginate(10),
        ]);
    }

    public function cancelPlaceholder(Request $request): RedirectResponse
    {
        return back()->with('success', 'Cancel subscription placeholder is ready. Real cancellation rules will be added when payment provider billing is connected.');
    }
}
