<?php

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

Route::get('/', fn () => auth()->check() ? redirect()->route('dashboard') : redirect()->route('login'));

Route::middleware('guest')->group(function (): void {
    Route::get('/register', [AuthController::class, 'showRegister'])->name('register');
    Route::post('/register', [AuthController::class, 'register'])->name('register.store');
    Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
    Route::post('/login', [AuthController::class, 'login'])->name('login.store');
});

Route::post('/logout', [AuthController::class, 'logout'])->middleware('auth')->name('logout');

Route::middleware('auth')->group(function (): void {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

    Route::get('/monitor', [MonitorController::class, 'monitor'])->name('monitor.index');
    Route::get('/monitor/map-mapping', [MonitorController::class, 'mapping'])->name('monitor.mapping');
    Route::get('/monitor/states/{stateMap:slug}/traffic-map', [MonitorController::class, 'trafficMap'])->name('monitor.traffic-map');
    Route::get('/monitor/states/{stateMap:slug}/franchise-zones', [MonitorController::class, 'franchise'])->name('monitor.franchise-zones');
    Route::post('/monitor/states/{stateMap:slug}/franchise-zones', [MonitorController::class, 'saveFranchiseZones'])->name('monitor.franchise-zones.save');

    Route::get('/driver-payouts', [DriverPayoutController::class, 'index'])->name('driver-payouts.index');
    Route::post('/driver-payouts', [DriverPayoutController::class, 'store'])->name('driver-payouts.store');
    Route::put('/driver-payouts/{driverPayout}', [DriverPayoutController::class, 'update'])->name('driver-payouts.update');
    Route::delete('/driver-payouts/{driverPayout}', [DriverPayoutController::class, 'destroy'])->name('driver-payouts.destroy');
    Route::post('/driver-payouts/import', [DriverPayoutController::class, 'import'])->name('driver-payouts.import');
    Route::get('/driver-payouts/export', [DriverPayoutController::class, 'export'])->name('driver-payouts.export');
});
