<?php

use Illuminate\Support\Facades\Route;

Route::group(['middleware' => ['clean_data']], function () {
    // Route::post('/login', 'API\v1\AuthController@login');
    // Route::post('/logout', 'API\v1\AuthController@logout');
    Route::post('tenant/load', 'API\v1\TenantController@load_tenant');
    Route::post('tenants', 'API\v1\TenantController@store');// To create tenant base database and all




Route::group(['middleware' => ['check_access_token_is_set','switch_db']], function () {
    // HACK : delete this route later !
    Route::get('/notif-test', 'API\v1\NotificationController@test');

    // take the user informations from access_token
    Route::get('user/login/check_can_refresh', 'API\v1\UserController@check_can_refresh');
    Route::post('user/login/refresh_user_info', 'API\v1\UserController@refresh_user_info');

    // HACK: elearning index. remove it later
    Route::get('elearning/index', 'BaseController@elearningIndex');
    Route::post('filieres/filter', 'BaseController@filterFilieres');

    Route::post('user/send_mail', 'API\v1\MailController@send');

    Route::group(['middleware' => ['verify_user_token']], function () {



        //Get user profile
        Route::get('user/profile/{matricule?}','API\v1\UserController@get_profile');


        //Catalogs
        Route::get('catalogs', 'API\v1\CatalogController@index');

        //Students
        //Route::get('students', 'API\v1\StudentController@index');
        //Route::get('students/{student}', 'API\v1\StudentController@show');
        //Route::post('students', 'API\v1\StudentController@store');
        //Route::put('students/{student}', 'API\v1\StudentController@update');
        //Route::delete('students/{student}', 'API\v1\StudentController@delete');
        Route::get('students/courses','API\v1\StudentController@courses'); //


        //Etablissements
        Route::get('etablissements','API\v1\StudentController@get_school');

        Route::get('medias/{mediaId}','API\v1\MediaController@detail_media'); //Details sur un media

        //Teachers
        Route::get('teachers', 'API\v1\TeacherController@index');
        Route::get('teachers/{teacher}', 'API\v1\TeacherController@show');
        Route::post('teachers', 'API\v1\TeacherController@store');
        Route::put('teachers/{teacher}', 'API\v1\TeacherController@update');
        Route::delete('teachers/{teacher}', 'API\v1\TeacherController@delete');

        //Courses
        Route::get('courses', 'API\v1\CourseController@course_index');// Pour l'admin, avoir tous les ecues;
        Route::get('courses/prof', 'API\v1\CourseController@pcourse_index');// Pour le prof, avoir tous les ecues;
        Route::get('courses/{ecuId}/prof/chap', 'API\v1\CourseController@pcourse_show');// Pour le prof, avoir tous les chapitres ecue;
        //Route::get('courses/{course}', 'API\v1\CourseController@show'); // Avoir une ecue x
        Route::post('courses', 'API\v1\CourseController@store');
        //Route::put('courses/{course}', 'API\v1\CourseController@update');
        //Route::delete('courses/{course}', 'API\v1\CourseController@delete');
        Route::post('lessons', 'API\v1\CourseController@store_lesson');//medias
        Route::post('lessons/reorder', 'API\v1\CourseController@reorder_lesson');//medias

        // Route::post('courses/{course}/lessons', 'API\v1\CourseController@store_lesson');
        Route::get('courses/{ecuId}/lessons/{statut?}', 'API\v1\CourseController@index_lesson')->where('statut', '[A-Za-z]+'); // Prendre tous les medias d'une ecu
        //Route::get('lessons/{lesson_id}', 'API\v1\CourseController@show_lesson');
        Route::put('lessons/{lesson_id}', 'API\v1\CourseController@update_lesson');
        Route::delete('lessons/{lesson_id}', 'API\v1\CourseController@delete_lesson');

        //Notifications
        //Route::get('users/{userId}/notifs','API\v1\NotificationController@notifs_block');
        //Route::post('notif','API\v1\NotificationController@store_notification');
        Route::post('user/notifs','API\v1\NotificationController@all_notifs');
        Route::post('user/notifs/{notificationId}/update','API\v1\NotificationController@update');
        Route::post('user/notifs/update_choice','API\v1\NotificationController@update_choice');



        //Evaluations
        // Route::get('evaluations', 'API\v1\EvaluationController@index');
        // Route::get('evaluations/{evaluation}', 'API\v1\EvaluationController@show');
        // Route::post('evaluations', 'API\v1\EvaluationController@store');
        // Route::put('evaluations/{evaluation}', 'API\v1\EvaluationController@update');
        // Route::delete('evaluations/{evaluation}', 'API\v1\EvaluationController@delete');

        //Quiz
        Route::get('quizs', 'API\v1\QuizController@index');
        Route::get('quizs/{quizId}', 'API\v1\QuizController@show');
        Route::post('quizs', 'API\v1\QuizController@store');
        Route::put('quizs/{quizId}', 'API\v1\QuizController@update');
        Route::delete('quizs/{quizId}', 'API\v1\QuizController@delete');
        Route::get('chapitres/{chap_id}/quizzes', 'API\v1\CourseController@get_quizzes');


        //Comments
        /*
        Route::get('comments', 'API\v1\CommentController@index');
        Route::get('comments/{comment}', 'API\v1\CommentController@show');
        Route::post('comments', 'API\v1\CommentController@store');
        Route::put('comments/{comment}', 'API\v1\CommentController@update');
        Route::delete('comments/{comment}', 'API\v1\CommentController@delete');
        */

        //Comments

        Route::post('comment', 'API\v1\CommentController@store'); //
        Route::get('medias/{mediaId}/comments','API\v1\CommentController@showAll'); //
        // Route::get('medias/{mediaId}/comments_ordered','API\v1\CommentController@orderComment'); //
        Route::get('comment/{commentId}/comments','API\v1\CommentController@show'); //



        //Medias
        Route::get('medias/{mediaId}','API\v1\MediaController@get_media');
        Route::post('medias','API\v1\MediaController@store');
        Route::post('recent-medias','API\v1\MediaController@show_recent_medias');
        // Route::get('ues/medias/{ue}','API\v1\MediaController@ue_medias');

        Route::post('user-medias/{mediaId}','API\v1\MediaController@statut_media');
        Route::post('ecus/{ecuId}/medias','API\v1\MediaController@ecu_media');

        //Route::get('ecus/{ecu}/medias','API\v1\MediaController@ecu_medias');

        //Enseignants
        //Route::get('users/data', 'API\v1\StudentController@getUserData');

        //Ecus
        Route::get('ecus/{ecuId}','API\v1\StudentController@ecu_data');
        Route::get('ecus/{ecuId}/students','API\v1\StudentController@students_ecu');
        Route::get('ecus/{ecuId}/last-views','API\v1\MediaController@last_media_visualized');
        Route::get('ecus/{ecuId}/student-last-view','API\v1\MediaController@last_media');
        Route::post('student/last-views','API\v1\MediaController@medias_visualized_lastly');
        Route::get('student/last-view','API\v1\MediaController@get_last_viewed');
        Route::get('student/exam','API\v1\StudentController@exam');

        // Route::get('ecus/{ecu}/courses','API\v1\CourseController@ecu_courses'); a revoir

        // Users
        Route::post('users/{userId}/check_auth', 'API\v1\AuthController@check_auth');

    });

    Route::post('user/auth', 'API\v1\AuthController@auth'); // create or update
});

});

//Route::group(['middleware' => ['VerifyApiKey']], function () {
    // Route::post('/login', 'API\v1\AuthController@login');
    // Route::post('/logout', 'API\v1\AuthController@logout');
//});

//Route::group(['middleware' => ['VerifyUserToken']], function () {


   // Route::get('evaluations/docs','');
//});







