<?php

declare(strict_types=1);

namespace Maestro\Core\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Maestro\Core\Database\Seeders\ModuleAndNavigationSeeder;
use Maestro\Core\Services\NavigationTreeBuilder;

class NavigationController extends Controller
{
    public function __construct(
        private readonly NavigationTreeBuilder $navigationTreeBuilder
    ) {}

    public function index(Request $request): JsonResponse
    {
        ModuleAndNavigationSeeder::ensureDefaultsPresent();

        $user = $request->user();

        return response()->json($this->navigationTreeBuilder->buildForUser($user));
    }
}
