<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\View\DashboardRedirectController;
use App\Services\Docs\OpenApiRouteExporter;

Route::redirect('/', '/api/docs')->name('docs.home');
Route::view('/api/docs', 'docs.swagger')->name('docs.swagger');
Route::get('/dashboard', [DashboardRedirectController::class, 'dashboard'])->name('dashboard.redirect');

Route::get('/api/documentation/swagger.json', function () {
    $path = resource_path('docs/openapi.json');
    abort_unless(is_file($path), 404);

    $spec = app(OpenApiRouteExporter::class)->exportFromFile($path);

    return response()->json($spec, 200, [
        'Content-Type' => 'application/json',
        'Cache-Control' => 'no-store, max-age=0',
    ]);
})->name('docs.swagger-json');
