<?php

use App\Http\Controllers\Backend\AuthController;
use App\Http\Controllers\Backend\UsersController;
use App\Http\Controllers\Backend\FunmenusController;
use App\Http\Controllers\Backend\PasswordController;
use App\Http\Controllers\Backend\DashboardController;
use App\Http\Controllers\Backend\UsergroupsController;
use App\Http\Controllers\Backend\FunmenusDetailController;
use App\Http\Controllers\Backend\DataManagement\SignupManagementController;
use App\Http\Controllers\Backend\DataManagement\TrackManagementController;

// Fow AWS ELB 健康檢查
Route::get('/health-check', function () {
    return response('healthy');
});

Route::prefix('backend')->group(function () {
    Route::redirect('/', '/backend/login');

    // Authentication
    Route::get('/login', [AuthController::class, 'index'])
        ->middleware(['guest:web'])
        ->name('login.index');

    Route::post('/login', [AuthController::class, 'login'])
        ->middleware([
            'guest:web',
            // 'throttle:login'
        ])->name('login');

    Route::middleware(['auth'])->group(function () {

        Route::get('/dashboard', DashboardController::class)->name('backend.dashboard');

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

        // System ManagementChange Password
        Route::controller(PasswordController::class)->prefix('Password')->group(function () {
            Route::get('/', 'index');
            Route::post('/', 'update');
        });

        // System ManagementManage Groups
        Route::controller(UsergroupsController::class)->prefix('Usergroups')->group(function () {
            Route::get('/', 'index');
            Route::get('/create', 'create');
            Route::get('/edit/{id}', 'edit');
            Route::post('/store', 'store');
            Route::delete('/{id}', 'delete');
        });

        // System ManagementManage Users
        Route::controller(UsersController::class)->prefix('Users')->group(function () {
            Route::get('/', 'index');
            Route::get('/create', 'create');
            Route::get('/edit/{id}', 'edit');
            Route::post('/store', 'store');
            Route::delete('/{id}', 'delete');
        });

        // System ManagementManage Functions
        Route::controller(FunmenusController::class)->prefix('Funmenus')->group(function () {
            Route::get('/', 'index');
            Route::get('/create', 'create');
            Route::get('/edit/{id}', 'edit');
            Route::post('/store', 'store');
            Route::delete('/{id}', 'delete');
        });

        // System ManagementManage Functions Detail
        Route::controller(FunmenusDetailController::class)->prefix('Funmenus')->group(function () {
            Route::get('/{menuid}', 'index');
            Route::get('/{menuid}/create', 'create');
            Route::get('/{menuid}/edit/{id}', 'edit');
            Route::post('/{menuid}/store', 'store');
            Route::delete('/{menuid}/delete/{id}', 'delete');
        });
        
        // 報名資料查詢
        Route::controller(SignupManagementController::class)->prefix('dataManagement/signup')->group(function () {
            Route::get('/', 'index');
            Route::get('/grid', 'grid');
            Route::post('/export', 'export')->name('signup.export');
        });

        // 場次查詢
        Route::controller(TrackManagementController::class)->prefix('dataManagement/track')->group(function () {
            Route::get('/', 'index');
            Route::get('/grid', 'grid');
            Route::post('/create', 'create')->name('track.create');
            Route::get('/edit/{id}', 'edit');
            Route::post('/store', 'store');
            Route::get('/delete/{id}', 'delete');
        });

    });
});
