<?php

use App\Http\Controllers\CommitmentController;
use App\Http\Controllers\DocumentController;
use App\Http\Controllers\MapController;
use App\Http\Controllers\MetroLineController;
use App\Http\Controllers\MetroNodeController;
use App\Http\Controllers\ProjectController;
use App\Http\Controllers\ThemaController;
use Illuminate\Support\Facades\Route;

// Redirect root to map
Route::get('/', fn () => redirect('/map'));

// Authenticated routes
Route::middleware(['auth', 'verified'])->group(function () {
    // Metro Map
    Route::get('/map', [MapController::class, 'index'])->name('map');
    Route::get('/map/project/{project}', [MapController::class, 'project'])->name('map.project');

    // API endpoints for dynamic map data
    Route::prefix('api')->group(function () {
        Route::get('/map/strategy', [MapController::class, 'apiStrategy'])->name('api.map.strategy');
        Route::get('/map/project/{project}', [MapController::class, 'apiProject'])->name('api.map.project');
        Route::get('/map/node/{type}/{id}/children', [MapController::class, 'apiNodeChildren'])->name('api.map.node.children');
    });

    // Projects
    Route::post('/projects', [ProjectController::class, 'store'])->name('projects.store');
    Route::get('/projects/{project}', [ProjectController::class, 'show'])->name('projects.show');
    Route::put('/projects/{project}', [ProjectController::class, 'update'])->name('projects.update');
    Route::post('/projects/{project}/transition', [ProjectController::class, 'transition'])->name('projects.transition');
    Route::post('/projects/{project}/park', [ProjectController::class, 'park'])->name('projects.park');
    Route::post('/projects/{project}/stop', [ProjectController::class, 'stop'])->name('projects.stop');
    Route::delete('/projects/{project}', [ProjectController::class, 'destroy'])->name('projects.destroy');

    // Themas
    Route::get('/themas', [ThemaController::class, 'index'])->name('themas.index');
    Route::post('/themas', [ThemaController::class, 'store'])->name('themas.store');
    Route::put('/themas/{thema}', [ThemaController::class, 'update'])->name('themas.update');

    // Commitments
    Route::post('/commitments', [CommitmentController::class, 'store'])->name('commitments.store');
    Route::put('/commitments/{commitment}', [CommitmentController::class, 'update'])->name('commitments.update');
    Route::post('/commitments/{commitment}/complete', [CommitmentController::class, 'complete'])->name('commitments.complete');
    Route::delete('/commitments/{commitment}', [CommitmentController::class, 'destroy'])->name('commitments.destroy');

    // Documents
    Route::post('/documents', [DocumentController::class, 'store'])->name('documents.store');
    Route::get('/documents/{document}/download', [DocumentController::class, 'download'])->name('documents.download');
    Route::delete('/documents/{document}', [DocumentController::class, 'destroy'])->name('documents.destroy');

    // Metro Lines
    Route::post('/metro-lines', [MetroLineController::class, 'store'])->name('metro-lines.store');
    Route::delete('/metro-lines/{metroLine}', [MetroLineController::class, 'destroy'])->name('metro-lines.destroy');

    // Metro Nodes
    Route::post('/metro-nodes', [MetroNodeController::class, 'store'])->name('metro-nodes.store');
    Route::put('/metro-nodes/{metroNode}', [MetroNodeController::class, 'update'])->name('metro-nodes.update');
    Route::delete('/metro-nodes/{metroNode}', [MetroNodeController::class, 'destroy'])->name('metro-nodes.destroy');

    // Dashboard (redirects to map)
    Route::get('/dashboard', fn () => redirect('/map'))->name('dashboard');
});
