<?php

declare(strict_types=1);

namespace App\Http\Controllers\Account;

use App\Http\Controllers\Controller;
use App\Models\Plan;
use Inertia\Inertia;
use Inertia\Response;

class PlanController extends Controller
{
    public function index(): Response
    {
        $plans = Plan::query()
            ->where('status', 'active')
            ->orderBy('sort_order')
            ->orderBy('price')
            ->get()
            ->groupBy('service_type');

        return Inertia::render('Plans/Index', [
            'plansByType' => $plans,
        ]);
    }

    public function show(Plan $plan): Response
    {
        if ($plan->status !== 'active') {
            abort(404);
        }

        return Inertia::render('Plans/Show', [
            'plan' => $plan,
        ]);
    }
}
