<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\NdrtOfficerController;
use App\Http\Controllers\TrainingController;
use App\Http\Controllers\DeploymentController;
use App\Http\Controllers\ReportController;
use App\Http\Controllers\OperationsManagerController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

// Redirect root to login
Route::get('/', function () {
    return redirect()->route('login');
});

// Authentication Routes
Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('/login', [LoginController::class, 'login']);
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');

// Protected Routes (Require Authentication)
Route::middleware('auth')->group(function () {
    
    // Dashboard
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
    Route::get('/settings', [DashboardController::class, 'settings'])->name('settings');
    Route::get('/faqs', [DashboardController::class, 'faqs'])->name('faqs');
    Route::get('/support', [DashboardController::class, 'support'])->name('support');
    
    // NDRT Surge Management
    Route::resource('ndrt', NdrtOfficerController::class);
    Route::post('ndrt/{ndrt}/training/{training}/grade', [NdrtOfficerController::class, 'gradeTraining'])->name('ndrt.grade');

    // Trainings Management
    Route::resource('trainings', TrainingController::class);

    // Deployments Management
    Route::resource('deployments', DeploymentController::class);
    Route::patch('deployments/{deployment}/end-mission', [DeploymentController::class, 'endMission'])->name('deployments.end-mission');
    Route::patch('deployments/{deployment}/approve', [DeploymentController::class, 'approve'])->name('deployments.approve');
    Route::get('/deployments/officer-availability/{officerId}', [DeploymentController::class, 'getOfficerAvailability'])
    ->name('deployments.officer-availability');

    // Reports
    Route::get('reports', [ReportController::class, 'index'])->name('reports.index');
    Route::get('reports/export/{type}', [ReportController::class, 'export'])->name('reports.export');

    // Operations Manager Management (Admin only)
    Route::resource('operations-manager', OperationsManagerController::class)->only(['index', 'create', 'store', 'edit', 'update', 'destroy']);
    Route::get('notifications', [App\Http\Controllers\NotificationController::class, 'index'])->name('notifications.index');
});