<?php

use App\Http\Controllers\ActivitiesAttendedController;
use App\Http\Controllers\ActivitiesOrganisedController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\DepartmentController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\BooksPublishedController;
use App\Http\Controllers\CoordinatorController;
use App\Http\Controllers\ExternalEngagementController;
use App\Http\Controllers\FacultyController;
use App\Http\Controllers\IvOrganisedController;
use App\Http\Controllers\MissingProofsController;
use App\Http\Controllers\OnlineCoursesController;
use App\Http\Controllers\PatentsController;
use App\Http\Controllers\PublicationsController;
use App\Http\Middleware\CheckRole;
use App\Http\Controllers\FacultyProfileController;

Route::get('/', function () {
    return redirect('/login');
});

Route::get('/dashboard', function () {
    // Redirect users to different pages based on their role
    $user = auth()->user();

    if ($user->role->name === 'Admin') {
        return redirect()->route('admin.dashboard');
    } elseif ($user->role->name === 'Coordinator') {
        return redirect()->route('coordinator.dashboard');
    } elseif ($user->role->name === 'Faculty') {
        return redirect()->route('faculty.dashboard');
    } else {
        return abort(403, 'Unauthorized');
    }
})->middleware(['auth', 'verified'])->name('dashboard');


// Activities Attended common routes
Route::delete('/activities-attended/{id}', [ActivitiesAttendedController::class, 'destroy'])->name('activitiesAttended.destroy');

// Activities Organised common routes
Route::delete('/activities-organised/{id}', [ActivitiesOrganisedController::class, 'destroy'])->name('activitiesOrganised.destroy');

// Iv Organised common routes
Route::delete('/iv-organised/{id}', [IvOrganisedController::class, 'destroy'])->name('ivOrganised.destroy');

// Publications common routes
Route::delete('/publication/{id}', [PublicationsController::class, 'destroy'])->name('publications.destroy');

// Books Published common routes
Route::delete('/booksPublished/{id}', [BooksPublishedController::class, 'destroy'])->name('booksPublished.destroy');

// Books Published common routes
Route::delete('/externalEngagement/{id}', [ExternalEngagementController::class, 'destroy'])->name('externalEngagement.destroy');

// Books Published common routes
Route::delete('/onlineCourses/{id}', [OnlineCoursesController::class, 'destroy'])->name('onlineCourses.destroy');

// Books Published common routes
Route::delete('/patents/{id}', [PatentsController::class, 'destroy'])->name('patents.destroy');

// Admin routes
Route::middleware(['auth', CheckRole::class . ':Admin'])->group(function () {
    Route::get('/admin', [AdminController::class, 'index'])->name('admin.dashboard');
    Route::get('/admin/users', [UserController::class, 'index'])->name('admin.users.index');
    Route::get('/admin/users/data', [UserController::class, 'getUsersData'])->name('admin.users.data');


    // Activities Attended Routes
    Route::get('/admin/ActivitiesAttendedResponses', [AdminController::class, 'viewActivitiesAttendedResponses'])->name('admin.ActivitiesAttendedResponses');
    Route::get('/admin/ActivitiesAttendedResponses/data', [ActivitiesAttendedController::class, 'getActivitiesAttendedResponses'])->name('admin.ActivitiesAttendedResponses.data');
    Route::get('/admin/activities-attended/{id}/edit', [ActivitiesAttendedController::class, 'edit'])->name('admin.ActivitiesAttended.edit');
    Route::put('/admin/activities-attended/{id}', [ActivitiesAttendedController::class, 'update'])->name('admin.ActivitiesAttended.update');
    Route::delete('/admin/activities-attended/{id}', [ActivitiesAttendedController::class, 'destroy'])->name('admin.ActivitiesAttended.destroy');

    // Activities Organised Routes
    Route::get('/admin/ActivitiesOrganisedResponses', [AdminController::class, 'viewActivitiesOrganisedResponses'])->name('admin.ActivitiesOrganisedResponses');
    Route::get('/admin/ActivitiesOrganisedResponses/data', [ActivitiesOrganisedController::class, 'getActivitiesOrganisedResponses'])->name('admin.ActivitiesOrganisedResponses.data');
    Route::get('/admin/activities-organised/{id}/edit', [ActivitiesOrganisedController::class, 'edit'])->name('admin.ActivitiesOrganised.edit');
    Route::put('/admin/activities-organised/{id}', [ActivitiesOrganisedController::class, 'update'])->name('admin.ActivitiesOrganised.update');
    Route::delete('/admin/activities-organised/{id}', [ActivitiesOrganisedController::class, 'destroy'])->name('admin.ActivitiesOrganised.destroy');

    // IV Organised Routes
    Route::get('/admin/IvOrganisedResponses', [AdminController::class, 'viewIvOrganisedResponses'])->name('admin.IvOrganisedResponses');
    Route::get('/admin/IvOrganisedResponses/data', [IvOrganisedController::class, 'getIvOrganisedResponses'])->name('admin.IvOrganisedResponses.data');
    Route::get('/admin/iv-organised/{id}/edit', [IvOrganisedController::class, 'edit'])->name('admin.IvOrganised.edit');
    Route::put('/admin/iv-organised/{id}', [IvOrganisedController::class, 'update'])->name('admin.IvOrganised.update');
    Route::delete('/admin/iv-organised/{id}', [IvOrganisedController::class, 'destroy'])->name('admin.IvOrganised.destroy');

    // Publications Routes
    Route::get('/admin/PublicationsResponses', [AdminController::class, 'viewPublicationsResponses'])->name('admin.PublicationsResponses');
    Route::get('/admin/PublicationsResponses/data', [PublicationsController::class, 'getPublicationsResponses'])->name('admin.PublicationsResponses.data');
    Route::get('/admin/publication/{id}/edit', [PublicationsController::class, 'edit'])->name('admin.Publications.edit');
    Route::put('/admin/publication/{id}', [PublicationsController::class, 'update'])->name('admin.Publications.update');
    Route::delete('/admin/publication/{id}', [PublicationsController::class, 'destroy'])->name('admin.Publications.destroy');

    // Books Published Routes
    Route::get('/admin/BooksPublishedResponses', [AdminController::class, 'viewBooksPublishedResponses'])->name('admin.BooksPublishedResponses');
    Route::get('/admin/BooksPublishedResponses/data', [BooksPublishedController::class, 'getBooksPublishedResponses'])->name('admin.BooksPublishedResponses.data');
    Route::get('/admin/booksPublished/{id}/edit', [BooksPublishedController::class, 'edit'])->name('admin.BooksPublished.edit');
    Route::put('/admin/booksPublished/{id}', [BooksPublishedController::class, 'update'])->name('admin.BooksPublished.update');
    Route::delete('/admin/booksPublished/{id}', [BooksPublishedController::class, 'destroy'])->name('admin.BooksPublished.destroy');

    // ExternalEngagement Routes
    Route::get('/admin/ExternalEngagementResponses', [AdminController::class, 'viewExternalEngagementResponses'])->name('admin.ExternalEngagementResponses');
    Route::get('/admin/ExternalEngagementResponses/data', [ExternalEngagementController::class, 'getExternalEngagementResponses'])->name('admin.ExternalEngagementResponses.data');
    Route::get('/admin/ExternalEngagement/{id}/edit', [ExternalEngagementController::class, 'edit'])->name('admin.ExternalEngagement.edit');
    Route::put('/admin/ExternalEngagement/{id}', [ExternalEngagementController::class, 'update'])->name('admin.ExternalEngagement.update');
    Route::delete('/admin/ExternalEngagement/{id}', [ExternalEngagementController::class, 'destroy'])->name('admin.ExternalEngagement.destroy');

    // OnlineCourses Routes
    Route::get('/admin/OnlineCoursesResponses', [AdminController::class, 'viewOnlineCoursesResponses'])->name('admin.OnlineCoursesResponses');
    Route::get('/admin/OnlineCoursesResponses/data', [OnlineCoursesController::class, 'getOnlineCoursesResponses'])->name('admin.OnlineCoursesResponses.data');
    Route::get('/admin/OnlineCourses/{id}/edit', [OnlineCoursesController::class, 'edit'])->name('admin.OnlineCourses.edit');
    Route::put('/admin/OnlineCourses/{id}', [OnlineCoursesController::class, 'update'])->name('admin.OnlineCourses.update');
    Route::delete('/admin/OnlineCourses/{id}', [OnlineCoursesController::class, 'destroy'])->name('admin.OnlineCourses.destroy');

    // Patents Routes
    Route::get('/admin/PatentsResponses', [AdminController::class, 'viewPatentsResponses'])->name('admin.PatentsResponses');
    Route::get('/admin/PatentsResponses/data', [PatentsController::class, 'getPatentsResponses'])->name('admin.PatentsResponses.data');
    Route::get('/admin/Patents/{id}/edit', [PatentsController::class, 'edit'])->name('admin.Patents.edit');
    Route::put('/admin/Patents/{id}', [PatentsController::class, 'update'])->name('admin.Patents.update');
    Route::delete('/admin/Patents/{id}', [PatentsController::class, 'destroy'])->name('admin.Patents.destroy');

});

// Coordinator routes
Route::middleware(['auth', CheckRole::class . ':Coordinator'])->group(function () {
    Route::get('/coordinator', [CoordinatorController::class, 'index'])->name('coordinator.dashboard');

    // Activities Attended Routes
    Route::get('/coordinator/ActivitiesAttendedResponses', [CoordinatorController::class, 'viewActivitiesAttendedResponses'])->name('coordinator.ActivitiesAttendedResponses');
    Route::get('/coordinator/ActivitiesAttendedResponses/data', [ActivitiesAttendedController::class, 'getActivitiesAttendedResponses'])->name('coordinator.ActivitiesAttendedResponses.data');
    Route::get('/coordinator/activities-attended/{id}/edit', [ActivitiesAttendedController::class, 'edit'])->name('coordinator.ActivitiesAttended.edit');
    Route::put('/coordinator/activities-attended/{id}', [ActivitiesAttendedController::class, 'update'])->name('coordinator.ActivitiesAttended.update');
    Route::delete('/coordinator/activities-attended/{id}', [ActivitiesAttendedController::class, 'destroy'])->name('coordinator.ActivitiesAttended.destroy');

    // Activities Organised Routes
    Route::get('/coordinator/ActivitiesOrganisedResponses', [CoordinatorController::class, 'viewActivitiesOrganisedResponses'])->name('coordinator.ActivitiesOrganisedResponses');
    Route::get('/coordinator/ActivitiesOrganisedResponses/data', [ActivitiesOrganisedController::class, 'getActivitiesOrganisedResponses'])->name('coordinator.ActivitiesOrganisedResponses.data');
    Route::get('/coordinator/activities-organised/{id}/edit', [ActivitiesOrganisedController::class, 'edit'])->name('coordinator.ActivitiesOrganised.edit');
    Route::put('/coordinator/activities-organised/{id}', [ActivitiesOrganisedController::class, 'update'])->name('coordinator.ActivitiesOrganised.update');
    Route::delete('/coordinator/activities-organised/{id}', [ActivitiesOrganisedController::class, 'destroy'])->name('coordinator.ActivitiesOrganised.destroy');

    // Iv Organised Routes
    Route::get('/coordinator/IvOrganisedResponses', [CoordinatorController::class, 'viewIvOrganisedResponses'])->name('coordinator.IvOrganisedResponses');
    Route::get('/coordinator/IvOrganisedResponses/data', [IvOrganisedController::class, 'getIvOrganisedResponses'])->name('coordinator.IvOrganisedResponses.data');
    Route::get('/coordinator/iv-organised/{id}/edit', [IvOrganisedController::class, 'edit'])->name('coordinator.IvOrganised.edit');
    Route::put('/coordinator/iv-organised/{id}', [IvOrganisedController::class, 'update'])->name('coordinator.IvOrganised.update');
    Route::delete('/coordinator/iv-organised/{id}', [IvOrganisedController::class, 'destroy'])->name('coordinator.IvOrganised.destroy');

    // Publications Routes
    Route::get('/coordinator/PublicationsResponses', [CoordinatorController::class, 'viewPublicationsResponses'])->name('coordinator.PublicationsResponses');
    Route::get('/coordinator/PublicationsResponses/data', [PublicationsController::class, 'getPublicationsResponses'])->name('coordinator.PublicationsResponses.data');
    Route::get('/coordinator/publication/{id}/edit', [PublicationsController::class, 'edit'])->name('coordinator.Publications.edit');
    Route::put('/coordinator/publication/{id}', [PublicationsController::class, 'update'])->name('coordinator.Publications.update');
    Route::delete('/coordinator/publication/{id}', [PublicationsController::class, 'destroy'])->name('coordinator.Publications.destroy');

    // BooksPublished Routes
    Route::get('/coordinator/BooksPublishedResponses', [CoordinatorController::class, 'viewBooksPublishedResponses'])->name('coordinator.BooksPublishedResponses');
    Route::get('/coordinator/BooksPublishedResponses/data', [BooksPublishedController::class, 'getBooksPublishedResponses'])->name('coordinator.BooksPublishedResponses.data');
    Route::get('/coordinator/booksPublished/{id}/edit', [BooksPublishedController::class, 'edit'])->name('coordinator.BooksPublished.edit');
    Route::put('/coordinator/booksPublished/{id}', [BooksPublishedController::class, 'update'])->name('coordinator.BooksPublished.update');
    Route::delete('/coordinator/booksPublished/{id}', [BooksPublishedController::class, 'destroy'])->name('coordinator.BooksPublished.destroy');

    // ExternalEngagement Routes
    Route::get('/coordinator/ExternalEngagementResponses', [CoordinatorController::class, 'viewExternalEngagementResponses'])->name('coordinator.ExternalEngagementResponses');
    Route::get('/coordinator/ExternalEngagementResponses/data', [ExternalEngagementController::class, 'getExternalEngagementResponses'])->name('coordinator.ExternalEngagementResponses.data');
    Route::get('/coordinator/ExternalEngagement/{id}/edit', [ExternalEngagementController::class, 'edit'])->name('coordinator.ExternalEngagement.edit');
    Route::put('/coordinator/ExternalEngagement/{id}', [ExternalEngagementController::class, 'update'])->name('coordinator.ExternalEngagement.update');
    Route::delete('/coordinator/ExternalEngagement/{id}', [ExternalEngagementController::class, 'destroy'])->name('coordinator.ExternalEngagement.destroy');

    // OnlineCourses Routes
    Route::get('/coordinator/OnlineCoursesResponses', [CoordinatorController::class, 'viewOnlineCoursesResponses'])->name('coordinator.OnlineCoursesResponses');
    Route::get('/coordinator/OnlineCoursesResponses/data', [OnlineCoursesController::class, 'getOnlineCoursesResponses'])->name('coordinator.OnlineCoursesResponses.data');
    Route::get('/coordinator/OnlineCourses/{id}/edit', [OnlineCoursesController::class, 'edit'])->name('coordinator.OnlineCourses.edit');
    Route::put('/coordinator/OnlineCourses/{id}', [OnlineCoursesController::class, 'update'])->name('coordinator.OnlineCourses.update');
    Route::delete('/coordinator/OnlineCourses/{id}', [OnlineCoursesController::class, 'destroy'])->name('coordinator.OnlineCourses.destroy');

    // Patents Routes
    Route::get('/coordinator/PatentsResponses', [CoordinatorController::class, 'viewPatentsResponses'])->name('coordinator.PatentsResponses');
    Route::get('/coordinator/PatentsResponses/data', [PatentsController::class, 'getPatentsResponses'])->name('coordinator.PatentsResponses.data');
    Route::get('/coordinator/Patents/{id}/edit', [PatentsController::class, 'edit'])->name('coordinator.Patents.edit');
    Route::put('/coordinator/Patents/{id}', [PatentsController::class, 'update'])->name('coordinator.Patents.update');
    Route::delete('/coordinator/Patents/{id}', [PatentsController::class, 'destroy'])->name('coordinator.Patents.destroy');
});

// Faculty routes
Route::middleware(['auth', CheckRole::class . ':Faculty'])->group(function () {
    Route::get('/faculty', [FacultyController::class, 'index'])->name('faculty.dashboard');

    // Faculty Profile Routes - KEPT AS REQUESTED
    Route::get('/faculty/profile', [FacultyProfileController::class, 'index'])->name('faculty.profile.index');
    Route::get('/faculty/profile/edit', [FacultyProfileController::class, 'edit'])->name('faculty.profile.edit');
    Route::put('/faculty/profile', [FacultyProfileController::class, 'update'])->name('faculty.profile.update');

    // Activities Attended Routes
    Route::get('/faculty/ActivitiesAttendedForm', [FacultyController::class, 'ActivitiesAttendedForm'])->name('faculty.ActivitiesAttendedForm');
    Route::post('/faculty/ActivitiesAttendedFormResponse', [FacultyController::class, 'ActivitiesAttendedFormResponse'])->name('faculty.ActivitiesAttendedFormResponse');
    Route::get('/faculty/ActivitiesAttendedResponses', [FacultyController::class, 'viewActivitiesAttendedResponses'])->name('faculty.ActivitiesAttendedResponses');
    Route::get('/faculty/ActivitiesAttendedResponses/data', [ActivitiesAttendedController::class, 'getActivitiesAttendedResponses'])->name('faculty.ActivitiesAttendedResponses.data');
    Route::get('/faculty/activities-attended/{id}/edit', [ActivitiesAttendedController::class, 'edit'])->name('faculty.ActivitiesAttended.edit');
    Route::put('/faculty/activities-attended/{id}', [ActivitiesAttendedController::class, 'update'])->name('faculty.ActivitiesAttended.update');

    // Activities Organised Routes
    Route::get('/faculty/ActivitiesOrganisedForm', [FacultyController::class, 'ActivitiesOrganisedForm'])->name('faculty.ActivitiesOrganisedForm');
    Route::post('/faculty/ActivitiesOrganisedFormResponse', [FacultyController::class, 'ActivitiesOrganisedFormResponse'])->name('faculty.ActivitiesOrganisedFormResponse');
    Route::get('/faculty/ActivitiesOrganisedResponses', [FacultyController::class, 'viewActivitiesOrganisedResponses'])->name('faculty.ActivitiesOrganisedResponses');
    Route::get('/faculty/ActivitiesOrganisedResponses/data', [ActivitiesOrganisedController::class, 'getActivitiesOrganisedResponses'])->name('faculty.ActivitiesOrganisedResponses.data');
    Route::get('/faculty/activities-organised/{id}/edit', [ActivitiesOrganisedController::class, 'edit'])->name('faculty.ActivitiesOrganised.edit');
    Route::put('/faculty/activities-organised/{id}', [ActivitiesOrganisedController::class, 'update'])->name('faculty.ActivitiesOrganised.update');

    // Iv Organised Routes
    Route::get('/faculty/IvOrganisedForm', [FacultyController::class, 'IvOrganisedForm'])->name('faculty.IvOrganisedForm');
    Route::post('/faculty/IvOrganisedFormResponse', [FacultyController::class, 'IvOrganisedFormResponse'])->name('faculty.IvOrganisedFormResponse');
    Route::get('/faculty/IvOrganisedResponses', [FacultyController::class, 'viewIvOrganisedResponses'])->name('faculty.IvOrganisedResponses');
    Route::get('/faculty/IvOrganisedResponses/data', [IvOrganisedController::class, 'getIvOrganisedResponses'])->name('faculty.IvOrganisedResponses.data');
    Route::get('/faculty/iv-organised/{id}/edit', [IvOrganisedController::class, 'edit'])->name('faculty.IvOrganised.edit');
    Route::put('/faculty/iv-organised/{id}', [IvOrganisedController::class, 'update'])->name('faculty.IvOrganised.update');

    // Publications Routes
    Route::get('/faculty/PublicationsForm', [FacultyController::class, 'PublicationsForm'])->name('faculty.PublicationsForm');
    Route::post('/faculty/PublicationsFormResponse', [FacultyController::class, 'PublicationsFormResponse'])->name('faculty.PublicationsFormResponse');
    Route::get('/faculty/PublicationsResponses', [FacultyController::class, 'viewPublicationsResponses'])->name('faculty.PublicationsResponses');
    Route::get('/faculty/PublicationsResponses/data', [PublicationsController::class, 'getPublicationsResponses'])->name('faculty.PublicationsResponses.data');
    Route::get('/faculty/publication/{id}/edit', [PublicationsController::class, 'edit'])->name('faculty.Publications.edit');
    Route::put('/faculty/publication/{id}', [PublicationsController::class, 'update'])->name('faculty.Publications.update');

    // Books Published Routes
    Route::get('/faculty/BooksPublishedForm', [FacultyController::class, 'BooksPublishedForm'])->name('faculty.BooksPublishedForm');
    Route::post('/faculty/BooksPublishedFormResponse', [FacultyController::class, 'BooksPublishedFormResponse'])->name('faculty.BooksPublishedFormResponse');
    Route::get('/faculty/BooksPublishedResponses', [FacultyController::class, 'viewBooksPublishedResponses'])->name('faculty.BooksPublishedResponses');
    Route::get('/faculty/BooksPublishedResponses/data', [BooksPublishedController::class, 'getBooksPublishedResponses'])->name('faculty.BooksPublishedResponses.data');
    Route::get('/faculty/booksPublished/{id}/edit', [BooksPublishedController::class, 'edit'])->name('faculty.BooksPublished.edit');
    Route::put('/faculty/booksPublished/{id}', [BooksPublishedController::class, 'update'])->name('faculty.BooksPublished.update');

    // External Engagement Routes
    Route::get('/faculty/ExternalEngagementForm', [FacultyController::class, 'ExternalEngagementForm'])->name('faculty.ExternalEngagementForm');
    Route::post('/faculty/ExternalEngagementFormResponse', [FacultyController::class, 'ExternalEngagementFormResponse'])->name('faculty.ExternalEngagementFormResponse');
    Route::get('/faculty/ExternalEngagementResponses', [FacultyController::class, 'viewExternalEngagementResponses'])->name('faculty.ExternalEngagementResponses');
    Route::get('/faculty/ExternalEngagementResponses/data', [ExternalEngagementController::class, 'getExternalEngagementResponses'])->name('faculty.ExternalEngagementResponses.data');
    Route::get('/faculty/ExternalEngagement/{id}/edit', [ExternalEngagementController::class, 'edit'])->name('faculty.ExternalEngagement.edit');
    Route::put('/faculty/ExternalEngagement/{id}', [ExternalEngagementController::class, 'update'])->name('faculty.ExternalEngagement.update');

    // Online Courses Routes
    Route::get('/faculty/OnlineCoursesForm', [FacultyController::class, 'OnlineCoursesForm'])->name('faculty.OnlineCoursesForm');
    Route::post('/faculty/OnlineCoursesFormResponse', [FacultyController::class, 'OnlineCoursesFormResponse'])->name('faculty.OnlineCoursesFormResponse');
    Route::get('/faculty/OnlineCoursesResponses', [FacultyController::class, 'viewOnlineCoursesResponses'])->name('faculty.OnlineCoursesResponses');
    Route::get('/faculty/OnlineCoursesResponses/data', [OnlineCoursesController::class, 'getOnlineCoursesResponses'])->name('faculty.OnlineCoursesResponses.data');
    Route::get('/faculty/OnlineCourses/{id}/edit', [OnlineCoursesController::class, 'edit'])->name('faculty.OnlineCourses.edit');
    Route::put('/faculty/OnlineCourses/{id}', [OnlineCoursesController::class, 'update'])->name('faculty.OnlineCourses.update');

    // Patents Routes
    Route::get('/faculty/PatentsForm', [FacultyController::class, 'PatentsForm'])->name('faculty.PatentsForm');
    Route::post('/faculty/PatentsFormResponse', [FacultyController::class, 'PatentsFormResponse'])->name('faculty.PatentsFormResponse');
    Route::get('/faculty/PatentsResponses', [FacultyController::class, 'viewPatentsResponses'])->name('faculty.PatentsResponses');
    Route::get('/faculty/PatentsResponses/data', [PatentsController::class, 'getPatentsResponses'])->name('faculty.PatentsResponses.data');
    Route::get('/faculty/Patents/{id}/edit', [PatentsController::class, 'edit'])->name('faculty.Patents.edit');
    Route::put('/faculty/Patents/{id}', [PatentsController::class, 'update'])->name('faculty.Patents.update');

    // Google Scholar import routes (FIXED: changed fetchFromScholar to fetchScholar)
    Route::post('/faculty/publications/fetch-scholar', [PublicationsController::class, 'fetchScholar'])
        ->name('faculty.publications.fetchScholar');

    Route::post('/faculty/publications/import-scholar', [PublicationsController::class, 'importScholar'])
        ->name('faculty.publications.importScholar');

    Route::post('/faculty/publications/import-selected', [PublicationsController::class, 'importSelected'])
        ->name('faculty.publications.importSelected');
});

Route::post('/missing-proofs/check', [MissingProofsController::class, 'checkAndSendEmails'])->name('missing-proofs.check');

// API Resources
Route::apiResources([
    'roles' => RoleController::class,
    'departments' => DepartmentController::class,
    'users' => UserController::class,
]);

Route::get('/api/users', [UserController::class, 'getAllUserNames'])->name('api.users.index');

require __DIR__ . '/auth.php';

Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('analytics/activitiesAttended', [AdminController::class, 'analyticsActivitiesAttended'])->name('analytics.activitiesAttended');
    Route::get('analytics/activitiesOrganised', [AdminController::class, 'analyticsActivitiesOrganised'])->name('analytics.activitiesOrganised');
    Route::get('analytics/ivOrganised', [AdminController::class, 'analyticsIvOrganised'])->name('analytics.ivOrganised');
    Route::get('analytics/paperPublished', [AdminController::class, 'analyticsPaperPublished'])->name('analytics.paperPublished');
    Route::get('analytics/booksPublished', [AdminController::class, 'analyticsBooksPublished'])->name('analytics.booksPublished');
    Route::get('analytics/externalEngagement', [AdminController::class, 'analyticsExternalEngagement'])->name('analytics.externalEngagement');
    Route::get('analytics/onlineCourse', [AdminController::class, 'analyticsOnlineCourse'])->name('analytics.onlineCourse');
    Route::get('analytics/patent', [AdminController::class, 'analyticsPatent'])->name('analytics.patent');

    Route::get('analytics/comparison', [AdminController::class, 'analyticsComparison'])->name('analytics.comparison');
    Route::get('analytics/contribution', [AdminController::class, 'analyticsContribution'])->name('analytics.contribution');
});

Route::prefix('coordinator')->name('coordinator.')->group(function () {
    Route::get('analytics/activitiesAttended', [CoordinatorController::class, 'analyticsActivitiesAttended'])->name('analytics.activitiesAttended');
    Route::get('analytics/activitiesOrganised', [CoordinatorController::class, 'analyticsActivitiesOrganised'])->name('analytics.activitiesOrganised');
    Route::get('analytics/ivOrganised', [CoordinatorController::class, 'analyticsIvOrganised'])->name('analytics.ivOrganised');
    Route::get('analytics/paperPublished', [CoordinatorController::class, 'analyticsPaperPublished'])->name('analytics.paperPublished');
    Route::get('analytics/booksPublished', [CoordinatorController::class, 'analyticsBooksPublished'])->name('analytics.booksPublished');
    Route::get('analytics/externalEngagement', [CoordinatorController::class, 'analyticsExternalEngagement'])->name('analytics.externalEngagement');
    Route::get('analytics/onlineCourse', [CoordinatorController::class, 'analyticsOnlineCourse'])->name('analytics.onlineCourse');
    Route::get('analytics/patent', [CoordinatorController::class, 'analyticsPatent'])->name('analytics.patent');
    
    Route::get('analytics/comparison', [CoordinatorController::class, 'analyticsComparison'])->name('analytics.comparison');
    Route::get('analytics/contribution', [CoordinatorController::class, 'analyticsContribution'])->name('analytics.contribution');
});


Route::post('/admin/download-proofs', [AdminController::class, 'downloadProofs'])->name('admin.downloadProofs');
Route::post('/admin/download-proofs', [CoordinatorController::class, 'downloadProofs'])->name('admin.downloadProofs');

// Google Login Route
Route::get('/auth/google', [App\Http\Controllers\Auth\GoogleController::class, 'redirectToGoogle'])->name('google.login');
Route::get('/auth/google/callback', [App\Http\Controllers\Auth\GoogleController::class, 'handleGoogleCallback'])->name('google.callback');

// ✅ Fallback route alias to avoid 'profile.edit' missing error
Route::get('/profile', function () {
    return redirect()->route('faculty.profile.edit');
})->name('profile.edit');
