<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\EtablissementController;
use App\Http\Controllers\UniversiteController;
use App\Http\Controllers\StatutController;
use App\Http\Controllers\ProgicielController;
use App\Http\Controllers\PrioriteController;
use App\Http\Controllers\ModuleController;
use App\Http\Controllers\PreoccupationController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\EvaluationController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\adminController;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use App\Models\Users;
use App\Http\Middleware\LoadTenant;
use Illuminate\Support\Facades\Log;


Route::get('/', [DashboardController::class, 'connexion']);

Route::match(['get', 'post'], '/login', [DashboardController::class, 'login'])->name('login');

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

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

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

Route::get('/profile', [ProfileController::class, 'show'])->name('profile');

Route::get('etablissements', [EtablissementController::class, 'index'])->name('etablissements.index'); 
Route::get('etablissements/{id}', [EtablissementController::class, 'show'])->name('etablissements.show'); 
Route::get('etablissements/create', [EtablissementController::class, 'create'])->name('etablissements.create'); 

// Récupération des universites depuis une autre base de données
Route::get('universites', [UniversiteController::class, 'index'])->name('universites.index'); 
Route::get('universites/{id}', [UniversiteController::class, 'show'])->name('universites.show'); 
Route::get('universites/create', [UniversiteController::class, 'create'])->name('universites.create'); 

//Route oure les statuts
Route::get('statuts/create', [StatutController::class, 'create'])->name('statuts.create');
Route::post('statuts', [StatutController::class, 'store'])->name('statuts.store');



// Route pour les progiciels
Route::get('progiciels', [ProgicielController::class, 'index'])->name('progiciels.index');
Route::get('progiciels/create', [ProgicielController::class, 'create'])->name('progiciels.create');
Route::post('progiciels', [ProgicielController::class, 'store'])->name('progiciels.store');
Route::get('progiciels/{progiciel}/edit', [ProgicielController::class, 'edit'])->name('progiciels.edit');
Route::put('progiciels/{progiciel}', [ProgicielController::class, 'update'])->name('progiciels.update');
Route::delete('progiciels/{progiciel}', [ProgicielController::class, 'destroy'])->name('progiciels.destroy');

Route::get('priorites/create', [PrioriteController::class, 'create'])->name('priorites.create');
Route::post('priorites', [PrioriteController::class, 'store'])->name('priorites.store');

// Routes pour les modules
Route::get('modules', [ModuleController::class, 'index'])->name('modules.index');
Route::get('modules/create', [ModuleController::class, 'create'])->name('modules.create');
Route::post('modules', [ModuleController::class, 'store'])->name('modules.store');
Route::get('modules/{module}', [ModuleController::class, 'show'])->name('modules.show');
Route::get('modules/{module}/edit', [ModuleController::class, 'edit'])->name('modules.edit');
Route::put('modules/{module}', [ModuleController::class, 'update'])->name('modules.update');
Route::delete('modules/{module}', [ModuleController::class, 'destroy'])->name('modules.destroy');

Route::get('preoccupations', [PreoccupationController::class, 'index'])->name('preoccupations.index');
Route::get('preoccupations/create', [PreoccupationController::class, 'create'])->name('preoccupations.create');
Route::post('preoccupations', [PreoccupationController::class, 'store'])->name('preoccupations.store');
Route::get('preoccupations/{preoccupation}/edit', [PreoccupationController::class, 'edit'])->name('preoccupations.edit');
Route::put('preoccupations/{preoccupation}', [PreoccupationController::class, 'update'])->name('preoccupations.update');
Route::delete('preoccupations/{preoccupation}', [PreoccupationController::class, 'destroy'])->name('preoccupations.destroy');
Route::get('modules/by-progiciel/{progiciel_id}', [PreoccupationController::class, 'getModulesByProgiciel']);
Route::get('/preoccupations/{id}', [PreoccupationController::class, 'show'])->name('preoccupations.show');

Route::get('preoccupations/assign/{id}', [PreoccupationController::class, 'showAssignForm'])->name('preoccupations.assign');

Route::post('preoccupations/assign', [PreoccupationController::class, 'assign'])->name('preoccupations.assign.store');
Route::post('/preoccupations/assign', [PreoccupationController::class, 'assign'])->name('preoccupations.assign.store');


// Route::get('/sync-roles', [DashboardController::class, 'syncUserRoles']);


Route::get('/sync-roles', [DashboardController::class, 'syncRolesFromLocal']);



