<?php

declare(strict_types=1);

namespace App\Http\Controllers\Account;

use App\Http\Controllers\Controller;
use App\Models\Service;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class ServiceController extends Controller
{
    public function index(Request $request): Response
    {
        $services = $request->user()
            ->services()
            ->with('plan:id,name,service_type,price,billing_cycle')
            ->latest()
            ->get();

        return Inertia::render('Services/Index', [
            'services' => $services,
        ]);
    }

    public function show(Request $request, Service $service): Response
    {
        abort_unless($service->user_id === $request->user()->id, 403);

        $service->load([
            'plan:id,name,slug,description,service_type,price,billing_cycle,features',
            'subscription',
        ]);

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