<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProjectController;
use App\Http\Controllers\Web\ProjectController  as ProjectControllerAdmin;
use App\Http\Controllers\Web\CategoryController  as CategoryControllerAdmin;
use App\Http\Controllers\Web\LicenseController  as LicenseControllerAdmin;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\SeedController;
use App\Http\Controllers\Web\StateController;
use App\Http\Controllers\Web\CouponController;
use App\Http\Controllers\Firebase\MultiJoueurController;
use App\Http\Controllers\FirebaseController;
use App\Http\Controllers\Firebase\ScoreExamenController;
use App\Http\Controllers\Firebase\BannerController;



  




/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});


Route::get('/admin/dashboard', [StateController::class, 'index']);
Route::get('/admin/dashboard-admin', 'App\Http\Controllers\Web\StateController@indexAdmin')->name('admin.dashboard.indexAdmin');


//Route::get('/dashboard', 'DashboardController@index')->name('dashboard')->middleware('auth');

// Route::get('/admin/projects', function () {
//     return view('admin.projects');
// });

Route::get('/projects', [ProjectController::class, 'index']);
Route::get('/projects/json', [ProjectController::class, 'getProjectsJson']);
Route::get('/projects/{id}/json', [ProjectController::class, 'getProjectJson']);


// Routes pour le contrôleur ProjectController dans le namespace App\Admin\Controllers
// Route::prefix('admin')->group(function () {
//     Route::resource('projects', ProjectControllerAdmin::class);
// });



Route::get('/admin/licenses-indexbyser', 'App\Http\Controllers\Web\LicenseController@indexbyser')->name('admin.licenses.indexbyser');


Route::get('/admin/projects/{projectId}/categories', 'App\Http\Controllers\Web\ProjectController@showCategories')->name('admin.projects.categories');

Route::get('/admin/projects/categories/{project}', 'App\Http\Controllers\Web\ProjectController@showCategoriesByProjectId')->name('admin.projects.categories.byid');

Route::post('/admin/categories/storemulti', 'App\Http\Controllers\Web\CategoryController@storeMulti')->name('admin.categories.store.multi');

Route::get('/admin/categories/indexById/{id}/{type}', 'App\Http\Controllers\Web\CategoryController@indexById')->name('admin.categories.indexById');

Route::middleware('auth')->prefix('admin')->group(function () {

    Route::prefix('admin')->group(function () {
        Route::resource('licenses', 'App\Http\Controllers\Web\LicenseController')->names([
            'index' => 'admin.licenses.index',  
            'create' => 'admin.licenses.create', 
            'store' => 'admin.licenses.store', 
            'show' => 'admin.licenses.show',  
            'edit' => 'admin.licenses.edit',  
            'update' => 'admin.licenses.update',  
            'destroy' => 'admin.licenses.destroy',  
        ]);
    });
    
    Route::prefix('admin')->group(function () {
        Route::resource('categories', 'App\Http\Controllers\Web\CategoryController')->names([
            'index' => 'admin.categories.index', 
            'create' => 'admin.categories.create', 
            'store' => 'admin.categories.store', 
            'show' => 'admin.categories.show', 
            'edit' => 'admin.categories.edit', 
            'update' => 'admin.categories.update', 
            'destroy' => 'admin.categories.destroy', 
        ]);
    });
    
    Route::prefix('admin')->group(function () {
        Route::resource('applications', 'App\Http\Controllers\Web\ApplicationController')->names([
            'index' => 'admin.applications.index',  
            'create' => 'admin.applications.create',  
            'store' => 'admin.applications.store',  
            'show' => 'admin.applications.show',  
            'edit' => 'admin.applications.edit',  
            'update' => 'admin.applications.update', 
            'destroy' => 'admin.applications.destroy',  
        ]);
    });

    Route::resource('projects', 'App\Http\Controllers\Web\ProjectController')->names([
        'index' => 'admin.projects.index', // Nom personnalisé pour l'action index
        'create' => 'admin.projects.create', // Nom personnalisé pour l'action create
        'store' => 'admin.projects.store', // Nom personnalisé pour l'action store
        'show' => 'admin.projects.show', // Nom personnalisé pour l'action show
        'edit' => 'admin.projects.edit', // Nom personnalisé pour l'action edit
        'update' => 'admin.projects.update', // Nom personnalisé pour l'action update
        'destroy' => 'admin.projects.destroy', // Nom personnalisé pour l'action destroy
    ]);
    
    Route::resource('questions', 'App\Http\Controllers\Web\QuestionController')->names([
        'index' => 'admin.questions.index', 
        'create' => 'admin.questions.create', 
        'store' => 'admin.questions.store', 
        'show' => 'admin.questions.show', 
        'edit' => 'admin.questions.edit', 
        'update' => 'admin.questions.update', 
        'destroy' => 'admin.questions.destroy', 
    ]);

    Route::resource('answers', 'App\Http\Controllers\Web\AnswerController')->names([
        'index' => 'admin.answers.index', 
        'create' => 'admin.answers.create', 
        'store' => 'admin.answers.store', 
        'show' => 'admin.answers.show', 
        'edit' => 'admin.answers.edit', 
        'update' => 'admin.answers.update', 
        'destroy' => 'admin.answers.destroy', 
    ]);


    Route::get('/answers2/{answer}/edit', 'App\Http\Controllers\Web\AnswerController@editWeb')->name('admin.answers.edit2');
    Route::put('/answers2/{answer}', 'App\Http\Controllers\Web\AnswerController@update2')->name('admin.answers.update2');
    Route::delete('/answers2/{answer}', 'App\Http\Controllers\Web\AnswerController@destroy2')->name('admin.answers.destroy2');
    Route::get('/questions/{question}/answers/create', 'App\Http\Controllers\Web\AnswerController@create2')->name('admin.answers.create2');
    Route::post('/question/answer/create', 'App\Http\Controllers\Web\AnswerController@store2')->name('admin.answers.store2');

});


Route::prefix('admin')->group(function () {
    Route::resource('documents', 'App\Http\Controllers\Web\DocumentController')->names([
        'index' => 'admin.documents.index', 
        'create' => 'admin.documents.create', 
        'store' => 'admin.documents.store', 
        'show' => 'admin.documents.show', 
        'edit' => 'admin.documents.edit', 
        'update' => 'admin.documents.update', 
        'destroy' => 'admin.documents.destroy', 
    ]);
});

Route::prefix('admin')->group(function () {
    Route::resource('chapters', 'App\Http\Controllers\Web\ChapterController')->names([
        'index' => 'admin.chapters.index', 
        'create' => 'admin.chapters.create', 
        'store' => 'admin.chapters.store', 
        'show' => 'admin.chapters.show', 
        'edit' => 'admin.chapters.edit', 
        'update' => 'admin.chapters.update', 
        'destroy' => 'admin.chapters.destroy', 
    ]);
});

Route::prefix('admin')->group(function () {
    Route::resource('exercises', 'App\Http\Controllers\Web\ExerciseController')->names([
        'index' => 'admin.exercises.index', 
        'create' => 'admin.exercises.create', 
        'store' => 'admin.exercises.store', 
        'show' => 'admin.exercises.show', 
        'edit' => 'admin.exercises.edit', 
        'update' => 'admin.exercises.update', 
        'destroy' => 'admin.exercises.destroy', 
    ]);
});

Route::prefix('admin')->group(function () {
    Route::resource('settings', 'App\Http\Controllers\Web\SettingController')->names([
        'index' => 'admin.settings.index', 
        'create' => 'admin.settings.create', 
        'store' => 'admin.settings.store', 
        'show' => 'admin.settings.show', 
        'edit' => 'admin.settings.edit', 
        'update' => 'admin.settings.update', 
    ]);
});


Route::prefix('admin')->group(function () {
    Route::resource('dossiers', 'App\Http\Controllers\Web\DossierController')->names([
        'index' => 'admin.dossiers.index', 
        'create' => 'admin.dossiers.create', 
        'store' => 'admin.dossiers.store', 
        'show' => 'admin.dossiers.show', 
        'edit' => 'admin.dossiers.edit', 
        'update' => 'admin.dossiers.update', 
        'destroy' => 'admin.dossiers.destroy', 
    ]);
});

Route::prefix('firebase')->group(function () {
    Route::resource('multijoueur', 'App\Http\Controllers\Firebase\MultiJoueurController')->names([
        'index' => 'firebase.multijoueurs.index', 
        'create' => 'firebase.multijoueurs.create', 
        'store' => 'firebase.multijoueurs.store', 
        'show' => 'firebase.multijoueurs.show', 
        'edit' => 'firebase.multijoueurs.edit', 
        'update' => 'firebase.multijoueurs.update', 
        'destroy' => 'firebase.multijoueurs.destroy', 
    ]);
});

Route::get('/sessions/{sessionId}/players', [MultiJoueurController::class, 'getPlayersBySession'])->name('firebase.multijoueurs.players');


Route::post('/admin/dossiers/crenaux', 'App\Http\Controllers\Web\DossierController@crenaux')->name('admin.dossiers.crenaux');
Route::post('/admin/dossiers/coderoute', 'App\Http\Controllers\Web\DossierController@coderoute')->name('admin.dossiers.coderoute');


Route::post('/admin/chapters/storemulti', 'App\Http\Controllers\Web\ChapterController@storeMulti')->name('admin.chapters.storemulti');


Route::get('/admin/chapters/{id}/exercises', 'App\Http\Controllers\Web\ExerciseController@showExercisesByChapterId')->name('admin.chapters.exercises.byid');

Route::post('/admin/exercises/storemulti', 'App\Http\Controllers\Web\ExerciseController@storemulti')->name('admin.exercises.storemulti');

// Route::get('/web/projects', 'App\Http\Controllers\Web\ProjectController@index')->name('admin.projects.index');

// Route::get('/admin/projects', function () {
//     return view('admin.projects.index');
// });


/*
|--------------------------------------------------------------------------
 Routes pour l'authentification
|--------------------------------------------------------------------------
|
| Utilisation de sanctum
|
*/

// Routes pour l'authentification
Route::get('/login', 'App\Http\Controllers\AuthController@showLoginForm')->name('login');
Route::post('/login', 'App\Http\Controllers\AuthController@login');
Route::post('/logout', 'App\Http\Controllers\AuthController@logout')->name('logout');


// Route pour l'inscription
Route::get('/register', 'App\Http\Controllers\AuthController@showRegistrationForm')->name('register');
Route::post('/register', 'App\Http\Controllers\AuthController@register');

// URL pour les seedeers
Route::get('/seed', [SeedController::class, 'seed'])->name('seed');

Route::prefix('admin')->group(function () {
    Route::resource('coupons', CouponController::class);
});

Route::get('/admin/states/licenses', 'App\Http\Controllers\Web\LicenseController@states')->name('admin.licenses.states');


//Firebase
Route::get('/firebase/register', [FirebaseController::class, 'registerUser']);
Route::get('/firebase/store', [FirebaseController::class, 'storeData']);
Route::get('/firebase/data', [FirebaseController::class, 'getData']);
Route::get('/firebase/examens', [ScoreExamenController::class, 'index2']);

Route::get('/firebase/scoreexamens', [ScoreExamenController::class, 'index'])->name('firbase.examens.index');


/*
|--------------------------------------------------------------------------
 Routes pour Firebase Ticko 
|--------------------------------------------------------------------------
| c'est à partir d'ici que je met les routes qui sont en liens avec GPAPP et Ticko
|  
|
*/



// Route::get('/firebase/banners', [BannerController::class, 'index'])->name('firbase.banners.index');

Route::prefix('firebase/banners')->group(function () {
    Route::get('/', [App\Http\Controllers\Firebase\BannerController::class, 'index'])->name('banners.index');
    Route::get('/create', [App\Http\Controllers\Firebase\BannerController::class, 'create'])->name('banners.create');
    Route::post('/', [App\Http\Controllers\Firebase\BannerController::class, 'store'])->name('banners.store');
    Route::get('/{id}', [App\Http\Controllers\Firebase\BannerController::class, 'show'])->name('banners.show');
    Route::get('/{id}/edit', [App\Http\Controllers\Firebase\BannerController::class, 'edit'])->name('banners.edit');
    Route::put('/{id}', [App\Http\Controllers\Firebase\BannerController::class, 'update'])->name('banners.update');
    Route::delete('/{id}', [App\Http\Controllers\Firebase\BannerController::class, 'destroy'])->name('banners.destroy');
});

// API publique pour récupérer les banners actifs
Route::get('/api/banners/active', [App\Http\Controllers\Firebase\BannerController::class, 'getActiveBanners']);

Route::prefix('firebase/wallets')->name('wallets.')->group(function () {
    Route::get('/', [App\Http\Controllers\Firebase\WalletController::class, 'index'])->name('index');
    Route::get('/{walletId}/transactions', [App\Http\Controllers\Firebase\WalletController::class, 'transactions'])->name('transactions');
    Route::post('/adjust', [App\Http\Controllers\Firebase\WalletController::class, 'adjustBalance'])->name('adjust');
    Route::post('/refund', [App\Http\Controllers\Firebase\WalletController::class, 'refund'])->name('refund');
});


// Routes pour les profils utilisateurs
Route::prefix('user-profiles')->name('user-profiles.')->group(function () {
    Route::get('/', [App\Http\Controllers\Firebase\UserProfileController::class, 'index'])->name('index');
    
    // Routes pour les différentes collections liées à l'utilisateur
    Route::get('/{userId}/location-points', [App\Http\Controllers\Firebase\UserProfileController::class, 'locationPoints'])->name('location-points');
    Route::get('/{userId}/routes', [App\Http\Controllers\Firebase\UserProfileController::class, 'routes'])->name('routes');
    Route::get('/{userId}/reservations', [App\Http\Controllers\Firebase\UserProfileController::class, 'reservations'])->name('reservations');
    Route::get('/{userId}/wallet', [App\Http\Controllers\Firebase\UserProfileController::class, 'wallet'])->name('wallet');
    
    // Édition du profil
    Route::get('/{userId}/edit', [App\Http\Controllers\Firebase\UserProfileController::class, 'edit'])->name('edit');
    Route::put('/{userId}', [App\Http\Controllers\Firebase\UserProfileController::class, 'update'])->name('update');

    Route::get('/{userId}/location-points/create', [App\Http\Controllers\Firebase\UserProfileController::class, 'createLocationPoint'])->name('location-points.create');
    Route::post('/{userId}/location-points', [App\Http\Controllers\Firebase\UserProfileController::class, 'storeLocationPoint'])->name('location-points.store');
    Route::get('/{userId}/location-points/{pointId}/edit', [App\Http\Controllers\Firebase\UserProfileController::class, 'editLocationPoint'])->name('location-points.edit');
    Route::put('/{userId}/location-points/{pointId}', [App\Http\Controllers\Firebase\UserProfileController::class, 'updateLocationPoint'])->name('location-points.update');
    Route::delete('/{userId}/location-points/{pointId}', [App\Http\Controllers\Firebase\UserProfileController::class, 'deleteLocationPoint'])->name('location-points.delete');
});


// Routes pour les réservations
Route::prefix('reservations')->name('reservations.')->group(function () {
    Route::get('/', [App\Http\Controllers\Firebase\ReservationController::class, 'index'])->name('index');
    Route::get('/{reservationId}', [App\Http\Controllers\Firebase\ReservationController::class, 'show'])->name('show');
});

Route::post('/reservations/{reservationId}/cancel', [App\Http\Controllers\Firebase\ReservationController::class, 'cancel'])
    ->name('reservations.cancel');

// Route pour l'annulation manuelle
Route::post('/reservations/{reservationId}/cancel-manual', [App\Http\Controllers\Firebase\ReservationController::class, 'cancelManual'])
    ->name('reservations.cancel.manual');
    