<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ConnexionController;
use App\Http\Controllers\CreationCompteController;
use App\Http\Controllers\CreationClasseController;
use App\Http\Controllers\AccueilController;
use App\Http\Controllers\InscriptionController;
use App\Http\Controllers\ClasseController;
use App\Http\Controllers\EleveController;
use App\Http\Controllers\PayementController;
use App\Http\Controllers\ProfesseurController;
use App\Http\Controllers\MatiereController;
use App\Http\Controllers\SearchController;
use App\Http\Controllers\CoursController;
use App\Http\Controllers\NoteController;
use App\Http\Controllers\AbsenceController;
use App\Http\Controllers\FactureController;
use App\Http\Controllers\OperationController;
use App\Http\Controllers\PromoController;
use App\Http\Controllers\RecuController;
use App\Http\Controllers\RapportPaiementController;

/*
|--------------------------------------------------------------------------
| 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!
|
*/
//Routes connexion
Route::get('/', [ConnexionController::class, 'formulaire']);
Route::post('/', [ConnexionController::class, 'traitement']);

Route::post('/upschool/payupcallback', [PayementController::class, 'payupCallback']);

//Route des utilisateur authentifié
Route::group([
    'middleware' => 'App\Http\Middleware\Auth',
], function () {
    //Route deconnexion
    Route::get('/deconnexion', [ConnexionController::class, 'deconnexion']);
    //Route set school_year
    Route::post('/setschoolyearvalue', [AccueilController::class, 'setCurrentYear'])->name('setSchoolYearValue.post');
    //Start new school year
    Route::post('/newpromo', [PromoController::class, 'createPromo']);
    //Reinitialisation
    Route::get('/upschool/reinitialisationMotDePasse/', [CreationCompteController::class, 'reinitialisation'])->name('reinitialisation');
    Route::post('/upschool/reinitialisationMotDePasse/{user_slug}', [CreationCompteController::class, 'reinitialiser']);

    //Routes des prof et eleve
    /* Route::group([
        'middleware' => 'App\Http\Middleware\EleveOrProfAuthenticated',
    ], function(){
        Route::get('/upschool/reinitialisationMotDePasse/', [CreationCompteController::class, 'reinitialisation'])->name('reinitialisation');
        Route::post('/upschool/reinitialisationMotDePasse/{user_slug}', [CreationCompteController::class, 'reinitialiser']);
    }); */

    //Routes des utilisateur eleve
    Route::group([
        'middleware' => 'App\Http\Middleware\EleveAuthenticated',
    ], function () {
        Route::get('/upschool/eleveDashboard/{eleve_slug}', [EleveController::class, 'afficherEleve'])->name('eleveDashboard');
        Route::get('/upschool/eleveDashboard/{eleve_slug}/{payement_id}/pay', [PayementController::class, 'onlinePayement']);
    });

    //Routes des utilisateur professeur
    Route::group([
        'middleware' => 'App\Http\Middleware\ProfAuthenticated',
    ], function () {
        Route::get('/upschool/profDashboard/{prof_slug}', [AccueilController::class, 'affichage'])->name('profDashboard');
    });

    //Route for admin and prof
    Route::group([
        'middleware' => 'App\Http\Middleware\ProfOrAdminAuthenticated',
    ], function () {
        //Route de la vue classe
        Route::get('/accueil/classe/{slug}', [ClasseController::class, 'affichage']);
        //Route Affichage eleve
        Route::get('/accueil/classe/{slug}/eleve/{eleve_slug}', [EleveController::class, 'affichage']);
        //Route Ajouter Cours
        Route::post('/accueil/classe/{id}/ajouterCours', [CoursController::class, 'ajouterCours']);
        //Route Ajouter Note
        Route::post('/accueil/classe/{slug}/enregistrerNotes', [NoteController::class, 'enregistrerNotes']);
        //Route historique evaluation
        Route::get('/accueil/classe/{slug}/evaluationHistory', [NoteController::class, 'evaluationHistory']);
        //Details evaluation
        Route::get('/accueil/classe/{slug}/evaluationHistory/{eval_slug}/details', [NoteController::class, 'detailsEvaluation']);
        //Ajouter Note
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/ajouterNote', [NoteController::class, 'ajouterNote']);
        //Historique des cours
        Route::get('/accueil/classe/{slug}/coursHistory', [CoursController::class, 'coursHistory']);
    });

    //Route for administration only
    Route::group([
        'middleware' => 'App\Http\Middleware\AdminAuthenticated',
    ], function () {
        //Routes creation de compte
        Route::get('/accueil/comptes', [CreationCompteController::class, 'formulaire']);
        Route::post('/creationCompte', [CreationCompteController::class, 'traitement']);
        Route::get('/accueil/comptes/compte/{slug}', [CreationCompteController::class, 'detailsCompte']);
        Route::post('/accueil/comptes/compte/{slug}/modifier', [CreationCompteController::class, 'modifier']);
        Route::post('/accueil/comptes/compte/{slug}/delete', [CreationCompteController::class, 'supprimer']);
        Route::post('/accueil/comptes/compte/{slug}/reinpassword', [CreationCompteController::class, 'reinPassword']);

        //Route affichage page d'accueil
        Route::get('/accueil', [AccueilController::class, 'affichage']);

        //Route creation de classe
        Route::post('/accueil/creationClasse', [CreationClasseController::class, 'traitement']);
        //Modification classe
        Route::post('/accueil/modifierClasse', [CreationClasseController::class, 'modifierClasse']);
        //Supprimer classe
        Route::post('/accueil/supprimerClasse', [CreationClasseController::class, 'supprimerClasse']);

        //Bulletin
        Route::get('/accueil/classe/{slug}/bulletins/{periode}', [ClasseController::class, 'bulletin']);

        //Factures
        Route::post('/factures/{classe_slug}', [FactureController::class, 'factures']);

        //Rapport Paiement
        Route::post('/rapportPaiement/{classe_slug}', [RapportPaiementController::class, 'rapportPaiement']);

        //Recu
        Route::get('/recu/{classe_slug}/{eleve_slug}/{paye_id}', [RecuController::class, 'recu']);

        //Promo
        Route::get('/accueil/classe/{slug}/{promo}', [ClasseController::class, 'displayPreviousPromo']);

        //Route inscription
        Route::post('/accueil/inscription', [InscriptionController::class, 'traitement']);

        //Routes pour les eleves
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}', [EleveController::class, 'update']);
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/delete', [EleveController::class, 'delete']);
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/reinscrire', [EleveController::class, 'reinscrire']);
        //Changer profil
        Route::post('/accueil/classe/{slug}/eleve/{id}/ajouterProfil', [EleveController::class, 'changerProfil']);

        //Route pour les payement
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/payement', [PayementController::class, 'traitement']);
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/payement/{payement_id}/payer', [PayementController::class, 'payerFrais']);
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/payement/{payement_id}/impayer', [PayementController::class, 'impayerFrais']);
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/payement/{payement_id}/modifier', [PayementController::class, 'modifierPayement']);
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/payement/{payement_id}/supprimer', [PayementController::class, 'supprimerPayement']);
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/payement/ajouterFrais', [PayementController::class, 'ajouterFrais']);

        //Routes pour les transactions
        Route::get('/accueil/operations', [OperationController::class, 'affichage']);
        Route::post('/accueil/operations/ajouterOperation', [OperationController::class, 'ajouterOperation']);
        Route::post('/accueil/operations/operation/{id}/modifier', [OperationController::class, 'modifierOperation']);
        Route::post('/accueil/operations/operation/{id}/supprimer', [OperationController::class, 'supprimerOperation']);
        Route::post('/accueil/operations/rapport', [OperationController::class, 'rapport']);
        Route::get('/accueil/operations/rapport/{debut}/{fin}', [OperationController::class, 'printRapport']);

        //Route des professeurs
        Route::get('/accueil/professeurs', [ProfesseurController::class, 'affichage']);
        Route::post('/accueil/professeurs/ajouterProf', [ProfesseurController::class, 'ajouterProf']);
        Route::get('/accueil/professeurs/detailsProf/{prof_slug}', [ProfesseurController::class, 'detailsProf']);
        Route::post('/accueil/professeurs/detailsProf/{prof_slug}/modifier', [ProfesseurController::class, 'modifier']);
        Route::post('/accueil/professeurs/detailsProf/{prof_slug}/supprimer', [ProfesseurController::class, 'supprimer']);

        //Route des matieres
        Route::get('/accueil/matieres', [MatiereController::class, 'affichage']);
        Route::post('/accueil/matieres/ajouterMatiere', [MatiereController::class, 'ajouterMatiere']);
        Route::post('/accueil/matieres/matiere/{id}/modifier', [MatiereController::class, 'modifierMatiere']);
        Route::post('/accueil/matieres/matiere/{id}/supprimer', [MatiereController::class, 'supprimerMatiere']);

        //Routes recherche navBar
        Route::post('/rechercheEleveNavBar', [EleveController::class, 'rechercher']);
        Route::get('/rechercheEleveNavBar/eleve/{eleve_slug}', [EleveController::class, 'affichage']);

        //Routes cours
        //Suppression cours
        Route::post('/accueil/classe/{slug}/coursHistory/{cours_id}/supprimer', [CoursController::class, 'supprimerCours']);
        //Modifier Cours
        Route::post('/accueil/classe/{slug}/coursHistory/{cours_id}/modifier', [CoursController::class, 'modifierCours']);

        //Notes
        //Supprimer note
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/notes/{note_id}/supprimer', [NoteController::class, 'supprimerNote']);
        //Modifier Note
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/notes/{note_id}/modifier', [NoteController::class, 'modifierNote']);
        //Absences
        Route::post('/accueil/classe/{slug}/eleve/{eleve_slug}/absences/{absence_id}/supprimer', [AbsenceController::class, 'supprimerAbsence']);
        //Routes des évaluations
        //Supprimer Evaluation
        Route::post('/accueil/classe/{slug}/evaluationHistory/{eval_id}/supprimer', [NoteController::class, 'supprimerEvaluation']);
        //Modifier Evaluation
        Route::post('/accueil/classe/{slug}/evaluationHistory/{eval_id}/modifier', [NoteController::class, 'modifierEvaluation']);
    });
});

//Route::view('/accueil', 'accueil');
