<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\MapFileController;

Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
Route::get('/api/maps', [DashboardController::class, 'getMapData'])->name('api.maps');

// AUTHENTICATION ROUTES
Route::get('/admin/login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('/admin/login', [AuthController::class, 'login'])->name('login.process');
Route::get('/admin/verify-otp', [AuthController::class, 'showOtpForm'])->name('otp.form');
Route::post('/admin/verify-otp', [AuthController::class, 'verifyOtp'])->name('otp.verify');
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

// ADMIN ROUTES (PROTECTED)
Route::middleware(['admin.otp'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/maps', [MapFileController::class, 'index'])->name('maps.index');
    Route::post('/maps', [MapFileController::class, 'store'])->name('maps.store');
    Route::delete('/maps/delete', [MapFileController::class, 'destroy'])->name('maps.destroy');
    Route::post('/maps/sync', [MapFileController::class, 'syncDatabase'])->name('maps.sync');
});
