<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\InspectionController;
use App\Http\Controllers\FindingController;
use App\Http\Controllers\EquipmentController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\ChecklistTemplateController;
use App\Http\Controllers\ReportController;
use Inertia\Inertia;

Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
Route::post('/login', [AuthController::class, 'login']);
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

// Public endpoint to get active users for the login screen
Route::get('/api/users', [UserController::class, 'apiIndex']);

Route::middleware('auth')->group(function () {
    Route::get('/', function () {
        return redirect()->route('dashboard');
    });

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

    Route::resource('inspections', InspectionController::class);
    Route::post('inspections/{inspection}/transition', [InspectionController::class, 'transition']);

    Route::resource('findings', FindingController::class);
    Route::post('findings/{finding}/transition', [FindingController::class, 'transition']);

    Route::resource('equipment', EquipmentController::class);
    Route::resource('users', UserController::class);
    Route::resource('checklists', ChecklistTemplateController::class);

    Route::get('/reports', [ReportController::class, 'index'])->name('reports');
});
