<?php

namespace App\Http\Controllers;

use App\Models\Account;
use Illuminate\Http\Request;

class AccountController extends Controller
{
    public function index()
    {
        $user = auth()->user();
        $accounts = Account::where('user_id', $user->id)->get();

        return view('dashboard.account', compact('user', 'accounts'));
    }

    public function upgrade(Request $request)
    {
        $validated = $request->validate([
            'tier' => ['required', 'in:Standard,Premium,VIP'],
        ]);

        $user = auth()->user();
        $user->update(['plan_type' => strtolower($validated['tier'])]);

        return back()->with('status', 'Plan upgraded to '.$validated['tier'].' successfully!');
    }
}
