<?php

use App\Http\Controllers\Fournisseur\CommandeFournisseurController;
use App\Http\Controllers\Fournisseur\MessageFournisseurController;
use App\Http\Controllers\Fournisseur\ProduitController;
use App\Http\Controllers\Fournisseur\CategorieFournisseurController;
use App\Http\Controllers\Fournisseur\EntrepriseFournisseurController;
use App\Http\Controllers\Fournisseur\ProfileController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;




use App\Http\Controllers\Userprofile;
use App\Http\Controllers\VerificationOptController;
use App\Http\Middleware\CheckEmailVerified;
use Illuminate\Support\Facades\Auth;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!



|
*/

Auth::routes();
//============maintenance=================================
Route::get('/', function () {
 return view('welcome');
});
//===================================================================================

Route::get('/auth', function () {
    return view('auth.login');
    // return view('welcome');
})->name('auths');



Route::get('/verification/code', [VerificationOptController::class, 'showVerificationForm'])->name('verification.code');
Route::post('/verification/verify', [VerificationOptController::class, 'verifyCode'])->name('verification.verify');
Route::post('/resendOTP',[VerificationOptController::class, 'resendOTP'])->name('resendOTP');
//======================================================================================================



// User Route
Route::middleware(['auth', CheckEmailVerified::class])->group(function () {

Route::get("/home", [HomeController::class, 'userHome'])->name('home');




Route::get('/user/{id}', [Userprofile::class, 'view'])->name('user.profile.view');
Route::get('/create', [Userprofile::class, 'create'])->name('user.profile.create');
Route::post('/store', [Userprofile::class, 'store'])->name('store');
Route::get('/edit/{id}', [Userprofile::class, 'edit'])->name('edit');
Route::post('/update', [Userprofile::class, 'update'])->name('update');
Route::post('/destroy/{id}', [Userprofile::class, 'destroy'])->name('destroy');

});


//=======================================================================================

// Editor Route

Route::middleware(['auth', 'user-role:editor'])->group(function () {
    Route::get("/editor/home", [HomeController::class, 'editorHome'])->name('home.editor');


});



// Admin Route
Route::middleware(['auth', 'user-role:admin'])->group(function () {
    Route::get("/admin/home", [HomeController::class, 'adminHome'])->name('home.admin');

    Route::resource("/Gestion+Produits",ProduitController::class);
    Route::get('/Produit/list', [ProduitController::class, 'list'])->name('Produits.list');
    Route::get('/Produit/edit/{id}', [ProduitController::class, 'edit'])->name('gestionProduits.edit');
    Route::put('/update+Produits', [ProduitController::class, 'update'])->name('update-Produits');
    Route::delete("/delete+Produits", [ProduitController::class, 'destroy'])->name('delete-Produits');

    Route::resource("/Gestion+Categorie",CategorieFournisseurController::class);
    Route::get('/Gestion+Categorie/edit/{id}', [CategorieFournisseurController::class, 'edit'])->name('gestionCategorie.edit');
    Route::put('/Categorie+Produit', [CategorieFournisseurController::class, 'update'])->name('update-Categorie');
    Route::delete("/delete+Categorie", [CategorieFournisseurController::class, 'destroy'])->name('delete-Categorie');


    Route::resource("/Gestion+Commande",CommandeFournisseurController::class);
    Route::delete("/delete+Commande", [CommandeFournisseurController::class, 'destroy'])->name('delete-Commande');


    Route::resource("/Gestion+Profil",ProfileController::class);
    Route::put('/Profil', [ProfileController::class, 'update'])->name('update-profile');
    Route::put('/User/Profil', [ProfileController::class, 'userInformation'])->name('user-profile-information.update');
    Route::put('/Password', [ProfileController::class, 'updatePassword'])->name('user-password.update');




    Route::resource("/Gestion+Entreprise",EntrepriseFournisseurController::class);
    Route::get('/Gestion+Entreprise/edit/{id}', [EntrepriseFournisseurController::class, 'edit'])->name('gestionEntreprise.edit');
    Route::put('/Entreprise+Produit', [EntrepriseFournisseurController::class, 'update'])->name('update-Entreprise');
    Route::delete("/delete+Entreprise", [EntrepriseFournisseurController::class, 'destroy'])->name('delete-Entreprise');
});
