<?php

// NOTE: https://laravel.com/docs/10.x/routing

use Illuminate\Support\Facades\Route;

/*

http actions mapping tables

https://laravel.com/docs/10.x/controllers#actions-handled-by-resource-controller

*/

use App\Http\Controllers\AdminController;
use App\Http\Controllers\AttendanceController;
use App\Http\Controllers\ClassRoomActivityController;
use App\Http\Controllers\ClassRoomController;
use App\Http\Controllers\CompanyController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\ExamController;
use App\Http\Controllers\ExamResultController;
use App\Http\Controllers\NoticeController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RegisterController;
use App\Http\Controllers\ScheduleController;
use App\Http\Controllers\SessionsController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\StudentDashboardController;
use App\Http\Controllers\SubjectController;
use App\Http\Controllers\TeacherController;
use App\Http\Controllers\UserController;

use App\Http\Controllers\HelloworldController;

// provide datatables
Route::prefix('dt')
  ->middleware('auth')
  ->group(function () {
    Route::get('/getAdmins', [AdminController::class, 'dtGetAdmins'])->name('dtGetAdmins');
    Route::get('/getAttendances', [AttendanceController::class, 'dtGetAttendances'])->name('dtGetAttendances');
    Route::get('/getAttendancesByTeacherId/{teacher_id}', [TeacherController::class, 'dtGetAttendancesByTeacherId'])->name('dtGetAttendancesByTeacherId');
    Route::get('/getClassrooms', [ClassRoomController::class, 'dtGetClassrooms'])->name('dtGetClassrooms');
    Route::get('/getExamResults', [ExamResultController::class, 'dtGetExamResults'])->name('dtGetExamResults');
    Route::get('/getExamResultsByStudentEmail/{student_email}', [ExamResultController::class, 'dtGetExamResultsByStudentEmail'])->name('dtGetExamResultsByStudentEmail');
    Route::get('/getExamResultsByTeacherId/{teacher_id}', [TeacherController::class, 'dtGetExamResultsByTeacherId'])->name('dtGetExamResultsByTeacherId');
    Route::get('/getExams', [ExamController::class, 'dtGetExams'])->name('dtGetExams');
    Route::get('/getExamsByTeacherId/{teacher_id}', [TeacherController::class, 'dtGetExamsByTeacherId'])->name('dtGetExamsByTeacherId');
    Route::get('/getNotices', [NoticeController::class, 'dtGetNotices'])->name('dtGetNotices');
    Route::get('/getPayments', [PaymentController::class, 'dtGetPayments'])->name('dtGetPayments');
    Route::get('/getSchedules', [ScheduleController::class, 'dtGetSchedules'])->name('dtGetSchedules');
    Route::get('/getSchedulesByTeacherId/{teacher_id}', [TeacherController::class, 'dtGetSchedulesByTeacherId'])->name('dtGetSchedulesByTeacherId');
    Route::get('/getSimpleExams', [ExamController::class, 'dtGetSimpleExams']);
    Route::get('/getSimpleSchedules', [ScheduleController::class, 'dtGetSimpleSchedules'])->name('dtGetSimpleSchedules');
    Route::get('/getStudents', [StudentController::class, 'dtGetStudents'])->name('dtGetStudents');
    Route::get('/getStudentSimpleExams/{student_id}', [StudentController::class, 'dtGetStudentSimpleExams']);
    Route::get('/getStudentSimpleSchedules/{student_id}', [StudentController::class, 'dtGetStudentSimpleSchedules']);
    Route::get('/getStudentUnreadNotices/{student_id}', [NoticeController::class, 'dtGetStudentUnreadNotices'])->name('dtGetStudentUnreadNotices');
    Route::get('/getSubjects', [SubjectController::class, 'dtGetSubjects'])->name('dtGetSubjects');
    Route::get('/getTeacherNotices/{teacher_id}', [TeacherController::class, 'dtGetTeacherNotices'])->name('dtGetTeacherNotices');
    Route::get('/getTeachers', [TeacherController::class, 'dtGetTeachers'])->name('dtGetTeachers');
    Route::get('/getTeacherSimpleExams/{teacher_id}', [TeacherController::class, 'dtGetTeacherSimpleExams']);
    Route::get('/getTeacherSimpleSchedules/{teacher_id}', [TeacherController::class, 'dtGetTeacherSimpleSchedules']);
    Route::get('/getUsers', [UserController::class, 'getUsers'])->name('dtGetUsers');

    Route::get('/helloworld', [HelloworldController::class, 'helloworld'])->name('getDtHelloworld');
  });

//
//
//
//
//
//

Route::prefix('json')
  ->middleware('auth')
  ->group(function () {
    Route::get('/getAttendances', [AttendanceController::class, 'getAttendancesJson'])->name('getAttendancesJson');
    Route::get('/getClassRooms', [ClassRoomController::class, 'getClassRoomsJson'])->name('getClassRoomsJson');
    Route::get('/getExamResults', [ExamResultController::class, 'getExamResultsJson'])->name('getExamResultsJson');
    Route::get('/getExams', [ExamController::class, 'getExamsJson'])->name('getExamsJson');
    Route::get('/getNotices', [NoticeController::class, 'getNoticesJson'])->name('getNoticesJson');
    Route::get('/getNumOfStudents', [StudentController::class, 'getNumOfStudents'])->name('getNumOfStudents');
    Route::get('/getPayments', [PaymentController::class, 'getPaymentsJson'])->name('getPaymentsJson');
    Route::get('/getStudents', [StudentController::class, 'getStudentsJson'])->name('getStudentsJson');
    Route::get('/getSubjects', [SubjectController::class, 'getSubjectsJson'])->name('getSubjectsJson');
    Route::get('/getTeachers', [TeacherController::class, 'getTeachersJson'])->name('getTeachersJson');
    Route::get('/getTeacherSchedule', [TeacherController::class, 'getTeacherScheduleJson'])->name('getTeacherScheduleJson');

    Route::get('/helloworld', [HelloworldController::class, 'helloworld'])->name('getJsonHelloworld');
  });

//
//
//
//
//
// NOTE: obsolete
Route::get('/listFreeClassRoom', [ClassRoomActivityController::class, 'listFreeClassRoom'])->name('listFreeClassRoom');
Route::get('/subjects/{id}/softdelete', [SubjectController::class, 'SoftDelete']);
Route::post('/createClassRoomActivity', [ClassRoomActivityController::class, 'createClassRoomActivity'])->name('createClassRoomActivity');
Route::get('/getStudentUnreadNoticesCount/{student_id}', [NoticeController::class, 'getStudentUnreadNoticesCount']);

Route::prefix('students')
  ->middleware('auth')
  ->controller(StudentController::class)
  ->group(function () {
    Route::get('/info', 'showInfo')->name('studentInfo');
    Route::put('/info', 'updateInfo');

    Route::get('/dashboard', 'showDashboard')->name('studentShowDashboard');

    // schedule
    Route::get('/showSchedules', 'showSchedules')->name('studentShowSchedules');

    // subject
    Route::get('/showSubjects', 'showSubjects')->name('studentShowSubjects');
    Route::put('/updateSubject', 'updateSubject');

    Route::get('/showExamResults', 'showExamResults')->name('studentShowExamResults');
    Route::get('/showExamResult/{exam_result_id}', 'showExamResult');

    Route::get('/showNotices', 'showNotices')->name('studentShowNotices');
    Route::get('/showNotice/{notice_id}', 'showNotice');
    Route::get('/setNoticeRead/{notice_id}', 'setNoticeRead')->name('studentSetNoticeRead');

    Route::get('/showNotifications', 'showNotifications')->name('studentShowNotifications');

    //
    //
    //
    // NOTE: obsolete
    Route::get('/clearAvatar', 'clearAvatar')->name('studentClearAvatar');

    Route::get('/helloworld', 'helloworld')->name('getStudentHelloworld');

    Route::get('/', 'helloworld')->name('getStudentHelloworld');
  });

//
//
//
//
//
//

Route::prefix('teachers')
  ->middleware('auth')
  ->controller(TeacherController::class)
  ->group(function () {
    Route::get('/dashboard', 'showDashboard')->name('teacherShowDashboard');

    Route::get('/showApplySubjects', 'showApplySubjects')->name('teacherShowApplySubjects');
    Route::get('/showSchedules', 'showSchedules')->name('teacherShowSchedules');
    Route::get('/showClassrooms', 'showClassrooms')->name('teacherShowClassrooms');

    Route::get('/showApplicableSchedules', 'showApplicableSchedules')->name('teacherShowApplicableSchedules');
    Route::get('/showExamResultsById/{exam_id}', 'showExamResultsById')->name('teacherShowExamResultsById');

    // Subject
    // NOTE: obsoleted
    Route::get('/showSubjects', 'showSubjects');

    Route::get('/viewSubjects', 'listSubject')->name('teacherShowSubject');
    Route::get('/viewSubject/{id}', 'viewSubject');

    Route::get('/editSubject/{id}', 'editSubject')->name('teacherEditSubject');
    Route::put('/editSubject/{id}', 'updateSubject');

    Route::put('/applySubject/{id}', 'applySubject')->name('teacherApplySubject');

    // Attendance
    // NOTE: obsolete
    Route::get('/showAttendances', 'showAttendances')->name('teacherShowAttendances');

    Route::get('/viewStudentAttendance/{schedule_id}', 'viewStudentAttendance')->name('viewStudentAttendance');
    Route::get('/showStudentAttendance/{schedule_id}', 'showStudentAttendance')->name('showStudentAttendance');
    Route::put('/teacherUpdateAttendance/{teacher_id}/{schedule_id}', 'updateAttendance')->name('teacherUpdateAttendance');
    Route::get('/teachers/EditAttendance/{attendance_id}', 'editAttendance')->name('teachersEditAttendance');
    Route::get('/teachers/ViewAttendance/{attendance_id}', 'viewAttendance')->name('teachersViewAttendance');

    // Exam
    Route::get('/viewExams', 'showExams')->name('teacherShowExams');
    Route::get('/viewExam/{exam_id}', 'viewExam');

    Route::get('/createExam', 'createExam')->name('teachersCreateExam');
    Route::post('/createExam', 'storeExam');

    Route::get('/editExam/{exam_id}', 'editExam')->name('teachersEditExam');
    Route::put('/editExam/{exam_id}', 'updateExam');
    Route::delete('/editExam/{exam_id}', 'destroyExam');

    // Exam result
    Route::put('/teacherUpdateExamResult/{teacher_id}/{exam_id}', 'updateExamResult')->name('teacherUpdateExamResult');

    // Schedule
    Route::get('/listSchedule', 'listSchedule')->name('teachersListSchedule');
    Route::get('/viewSchedule/{id}', 'viewSchedule')->name('teachersViewSchedule');

    Route::get('/createSchedule', 'createSchedule')->name('teachersCreateSchedule');
    Route::post('/createSchedule', 'storeSchedule');

    Route::get('/editSchedule/{id}', 'editSchedule')->name('teachersEditSchedule');
    Route::put('/editSchedule/{id}', 'updateSchedule')->name('teacherUpdateSchedule');
    Route::delete('/editSchedule/{id}', 'destroySchedule');

    // Notice
    Route::get('/viewNotice/{notice_id}', 'viewNotice')->name('teachersViewNotice');

    Route::get('/createNotice', 'createNotice')->name('teachersCreateNotice');
    Route::post('/createNotice', 'storeNotice');

    Route::get('/editNotice/{notice_id}', 'editNotice')->name('teachersEditNotice');
    Route::put('/editNotice/{notice_id}', 'updateNotice');
    Route::delete('/editNotice/{notice_id}', 'destroyNotice');

    Route::get('/getUnreadNoticesCount/{teacher_id}', 'getUnreadNoticeCount')->name('getTeacherUnreadNoticesCount');

    // Student
    Route::get('/viewStudents', 'listStudent')->name('teachersListStudent');
    Route::get('/viewStudent/{id}', 'viewStudent')->name('teachersViewStudent');

    Route::get('/createStudent', 'createStudent')->name('teachersCreateStudent');
    Route::post('/createStudent', 'storeStudent');

    Route::get('/editStudent/{student_id}', 'editStudent')->name('teachersEditStudent');
    Route::put('/editStudent/{student_id}', 'updateStudent');

    // info
    Route::get('/info', 'showInfo')->name('teacherInfo');
    Route::put('/info', 'updateInfo');

    // classroom
    Route::get('/viewClassRoom/{id}', 'viewClassRoom');

    //
    //
    //
    //
    //
    //

    Route::get('/showExamResult/{teacher_id}', 'showExamResult')->name('teacherShowExamResult');

    Route::get('/showNotices', 'showNotices')->name('teacherShowNotices');

    //
    //
    //
    // NOTE: obsoleted
    Route::get('/teacherShowNotifications', 'helloworld')->name('teacherShowNotifications');

    Route::get('/helloworld', 'helloworld')->name('getTeacherHelloworld');
  });

//
//
//
//
//
//

Route::prefix('admins')
  ->middleware('auth')
  ->controller(AdminController::class)
  ->group(function () {
    // NOTE: obsolete
    Route::get('/showAdminDashboard', 'showDashboard');

    Route::get('/dashboard', 'showDashboard')->name('adminShowDashboard');

    Route::get('/showPayments', 'showPayments')->name('adminShowPayments');
    Route::get('/viewPayments/{payment_id}', 'viewPayments')->name('adminViewPayment');
    Route::get('/editPayments/{payment_id}', 'editPayments')->name('adminEditPayment');
    Route::put('/editPayments/{payment_id}', 'updatePayment');

    Route::get('/createPayment', 'createPayment')->name('adminCreatePayment');
    Route::post('/createPayment', 'storePayment');
    Route::delete('/viewPayments/{payment_id}', 'adminDeletePayment');
    Route::get('/printPayments/{payment_id}', 'printPayment')->name('adminPrintPayment');

    Route::get('/helloworld', 'helloworld')->name('getAdminHelloworld');
  });

//
//
//
//
//
//

Route::resource('companies', CompanyController::class);
Route::resource('students', StudentController::class);
Route::resource('admins', AdminController::class);
Route::resource('teachers', TeacherController::class);
Route::resource('schedules', ScheduleController::class);
Route::resource('classrooms', ClassRoomController::class);
Route::resource('subjects', SubjectController::class);
Route::resource('attendances', AttendanceController::class);
Route::resource('exams', ExamController::class);
Route::resource('exam_results', ExamResultController::class);
Route::resource('payments', PaymentController::class);
Route::resource('notices', NoticeController::class);

Route::get('/students', function () {
  return redirect()->route('studentShowDashboard');
});

Route::get('/teachers', function () {
  return redirect()->route('teacherShowDashboard');
});

Route::get('/admins', function () {
  return redirect()->route('adminShowDashboard');
});

//
//
//
//
//
//

Route::prefix('/')
  ->middleware('auth')
  ->group(function () {
    Route::post('sign-out', [SessionsController::class, 'destroy'])->name('logout');
  });

Route::prefix('/')
  ->middleware('guest')
  ->group(function () {
    Route::get('sign-up', [RegisterController::class, 'registerTriage'])->name('register');
    Route::post('sign-up', [RegisterController::class, 'store']);

    Route::get('sign-in', [SessionsController::class, 'create'])->name('login');
    Route::post('sign-in', [SessionsController::class, 'store']);
    Route::post('reset-password', [SessionsController::class, 'update'])->name('password.update');
    Route::get('/reset-password/{token}', function ($token) {
      return view('sessions.password.reset', ['token' => $token]);
    })->name('password.reset');

    Route::get('verify', function () {
      return view('sessions.password.verify');
    })->name('verify');
    Route::post('verify', [SessionsController::class, 'show']);

    Route::get('sign-up-teacher', [RegisterController::class, 'createTeacher'])->name('register-teacher');
    Route::get('sign-up-student', [RegisterController::class, 'createStudent'])->name('register-student');

    Route::get('/', function () {
      return redirect('sign-in');
    });
  });

//
//
//
//
//
//

Route::get('/err_route', function () {
  return redirect('sign-in');
});

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

//
//
//
//
//
//

// NOTE: obsoleted
// Route::get('profile', [ProfileController::class, 'create'])
//   ->middleware('auth')
//   ->name('profile');
// Route::post('user-profile', [ProfileController::class, 'update'])->middleware('auth');

Route::prefix('helloworld')
  ->controller(HelloworldController::class)
  ->group(function () {
    // Route::get('/helloworld', 'helloworld')->name('getHelloworld');
  });

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

Route::get('/classrooms/{id}/softdelete', [HelloworldController::class, 'routeShouldBeObsoleted']);

Route::get('/helloworld', [HelloworldController::class, 'index'])->name('helloworld');

//
//
//
//
//
//

// demo Routes
Route::group(['middleware' => 'auth'], function () {
  Route::get('billing', function () {
    return view('pages.billing');
  })->name('billing');

  Route::get('tables', function () {
    return view('pages.tables');
  })->name('tables');

  Route::get('rtl', function () {
    return view('pages.rtl');
  })->name('rtl');

  Route::get('virtual-reality', function () {
    return view('pages.virtual-reality');
  })->name('virtual-reality');

  Route::get('notifications', function () {
    return view('pages.notifications');
  })->name('notifications');

  Route::get('static-sign-in', function () {
    return view('pages.static-sign-in');
  })->name('static-sign-in');

  Route::get('static-sign-up', function () {
    return view('pages.static-sign-up');
  })->name('static-sign-up');

  Route::get('user-management', function () {
    return view('pages.laravel-examples.user-management');
  })->name('user-management');

  Route::get('user-profile', function () {
    return view('pages.laravel-examples.user-profile');
  })->name('user-profile');
});
