<?php

use App\Http\Controllers\AboutController;
use App\Http\Controllers\AdmissionController;
use App\Http\Controllers\AlbumPhotoController;
use App\Http\Controllers\ContactController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\AlbumController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\AuthorController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\BlogController;
use App\Http\Controllers\FacilitiesController;
use App\Http\Controllers\FacilitiesPhotoController;
use App\Http\Controllers\FacultyController;
use App\Http\Controllers\PostController;
use App\Http\Controllers\ProgramsController;
use App\Http\Controllers\TesdaProgramsController;
use App\Http\Controllers\PhotoGalleryController;
use App\Http\Controllers\FacilitiesViewController;
use App\Http\Controllers\OfficesController;
use App\Http\Controllers\OfficesManageController;
use App\Http\Controllers\CarouselImageController;
use App\Http\Controllers\DownloadController;


Route::get('/cron',function(){
    if(request()->get('token') !== ('CRON_JOB_TOKEN')){
        abort(403, 'Unauthorized');
    }
    Artisan::call('queue:work --stop-when-empty');
    return response('Queue process successfully!');
});
//Home Route
Route::get('/', [HomeController::class, 'index'])->name('home');
//About Us Route
Route::get('/about/history', [AboutController::class, 'history'])->name('history');
Route::get('/about/core-values', [AboutController::class, 'coreValues'])->name('core_values');
Route::get('/about/vision-mission-goals', [AboutController::class, 'visionMissionGoals'])->name('vision_mission_goals');
Route::get('/about/administration', [AboutController::class, 'administration'])->name('administration');
Route::get('/about/organization-structure', [AboutController::class, 'organizationStructure'])->name('organization_structure');
Route::get('/about/pcds-logo', [AboutController::class, 'pcdsLogo'])->name('pcds_logo');
//Admission Route
Route::get('/admission/admission-policies', [AdmissionController::class, 'admissionPolicies'])->name('admission_policies');
Route::get('/admission/admission-procedure', [AdmissionController::class, 'admissionProcedure'])->name('admission_procedure');
Route::get('/admission/admission-requirements', [AdmissionController::class, 'admissionRequirements'])->name('admission_requirements');

//Offices Route
Route::get('/offices/associate-vice-president-for-academic-affairs', [OfficesController::class, 'associateVicePresidentForAcademicAffairs'])->name('associate_vice_president_for_academic_affairs');
Route::get('/offices/finance-department', [OfficesController::class, 'financeDepartment'])->name('finance_department');
Route::get('/offices/human-resources-department', [OfficesController::class, 'humanResourcesDepartment'])->name('human_resources_department');
Route::get('/offices/learning-resources-and-information-center', [OfficesController::class, 'learningResourcesAndInformationCenter'])->name('learning_resources_and_information_center');
Route::get('/offices/office-of-student-affairs', [OfficesController::class, 'officeOfStudentAffairs'])->name('office_of_student_affairs');
Route::get('/offices/presidents-office', [OfficesController::class, 'presidentsOffice'])->name('presidents_office');
Route::get('/offices/education-department/criminology-department', [OfficesController::class, 'criminologyDepartment'])->name('criminology_department');
Route::get('/offices/education-department/hospitality-management-department', [OfficesController::class, 'hospitalityManagementDepartment'])->name('hospitality_management_department');
Route::get('/offices/education-department/information-technology-department', [OfficesController::class, 'informationTechnologyDepartment'])->name('information_technology_department');
Route::get('/offices/education-department/nursing-department', [OfficesController::class, 'nursingDepartment'])->name('nursing_department');
Route::get('/offices/education-department/research-and-development', [OfficesController::class, 'researchAndDevelopment'])->name('research_and_development');
Route::get('/offices/education-department/radiologic-technology-department', [OfficesController::class, 'radiologicTechnologyDepartment'])->name('radiologic_technology_department');
Route::get('/offices/education-department/tesda-department', [OfficesController::class, 'tesdaDepartment'])->name('tesda_department');
Route::get('/offices/registrars-office', [OfficesController::class, 'registrarsOffice'])->name('registrars_office');

//Programs Route
Route::get('/programs/bs-criminology', [ProgramsController::class, 'bsCriminology'])->name('bs_criminology');
Route::get('/programs/bs-hospitality-management', [ProgramsController::class, 'bsHospitalityManagement'])->name('bs_hospitality_management');
Route::get('/programs/bs-information-technology', [ProgramsController::class, 'bsInformationTechnology'])->name('bs_information_technology');
Route::get('/programs/bs-nursing', [ProgramsController::class, 'bsNursing'])->name('bs_nursing');
Route::get('/programs/bs-radiologic-technology', [ProgramsController::class, 'bsRadiologicTechnology'])->name('bs_radiologic_technology');
Route::get('/programs/d-hotel-restaurant-technology', [ProgramsController::class, 'dHotelRestaurantTechnology'])->name('d_hotel_restaurant_technology');
//Tesda Programs Route
Route::get('/programs/tesda-programs/house-keeping', [TesdaProgramsController::class, 'houseKeeping'])->name('house_keeping');
Route::get('/programs/tesda-programs/food-and-beverages', [TesdaProgramsController::class, 'foodAndBeverages'])->name('food_and_beverages');
Route::get('/programs/tesda-programs/bartending', [TesdaProgramsController::class, 'bartending'])->name('bartending');
Route::get('/programs/tesda-programs/front-office', [TesdaProgramsController::class, 'frontOffice'])->name('front_office');
Route::get('/programs/tesda-programs/shielded-metal-arc-welding', [TesdaProgramsController::class, 'shieldedMetalArcWelding'])->name('shielded_metal_arc_welding');
Route::get('/programs/tesda-programs/automotive-servicing', [TesdaProgramsController::class, 'automotiveServicing'])->name('automotive_servicing');

//Bulletin Route
Route::get('/bulletin', [BlogController::class, 'index'])->name('bulletin');
Route::get('/bulletin/post/{slug}', [BlogController::class, 'readPost'])->name('read_post');
Route::get('/bulletin/posts/category/{slug}', [BlogController::class, 'categoryPosts'])->name('category_post');
Route::get('/bulletin/posts/author/{username}', [BlogController::class, 'authorPosts'])->name('author_posts');
Route::get('/bulletin/posts/tag/{any}', [BlogController::class, 'tagPosts'])->name('tag_posts');
Route::get('/bulletin/search', [BlogController::class, 'searchPosts'])->name('search_posts');

//Photo Gallery Route

Route::get('/photo-gallery', [PhotoGalleryController::class, 'index'])->name('photo_gallery');
Route::get('/photo-gallery/{album:slug}', [PhotoGalleryController::class, 'photoGalleryAlbum'])->name('photo_gallery_album');

//Facilities Gallery Route
Route::get('/facilities', [FacilitiesViewController::class, 'index'])->name('facilities');
Route::get('/facilities/{facilities:slug}', [FacilitiesViewController::class, 'facilitiesPhoto'])->name('facilities_photo');

//Contact Route

Route::get('/contact', [ContactController::class, 'contactUs'])->name('contact_us');
Route::view('/bernardo-tongcos', 'front.pages.tongcos')->name('tongcos');
Route::post('/contact', [ContactController::class, 'contactPost'])->name('contact.submit');
Route::get('/download', [DownloadController::class, 'index'])->name('downloadable_forms');
Route::get('/download/{filename}', [DownloadController::class, 'download'])->name('download.file');


Route::view('/example-page', 'example-page');
Route::view('/example-auth', 'example-auth');

Route::prefix('admin')->name('admin.')->group(function () {
    Route::middleware(['guest', 'preventBackHistory'])->group(function () {
        Route::controller(AuthController::class)->group(function () {
            Route::get('/login', 'loginForm')->name('login');
            Route::post('/login', 'loginHandler')->name('login_handler');
            Route::get('/forgot-password', 'forgotForm')->name('forgot');
            Route::post('/send-passwprd-reset-link', 'sendPasswordResetLink')->name('send_password_reset_link');
            Route::get('/password/reset/{token}', 'resetForm')->name('reset_password_form');
            Route::post('/reset-password-handler', 'resetPasswordHandler')->name('reset_password_handler');
        });
    });


    Route::middleware(['auth', 'preventBackHistory'])->group(function () {
        Route::controller(AdminController::class)->group(function () {
            Route::get('/dashboard', 'adminDashboard')->name('dashboard');
            Route::post('/logout', 'logoutHandler')->name('logout');
            Route::get('/profile', 'profileView')->name('profile');
            Route::post('/update-profile-picture', 'updateProfilePicture')->name('update_profile_picture');

            Route::middleware(['onlySuperAdmin'])->group(function () {
                Route::get('/settings', 'generalSettings')->name('settings');
                Route::post('/update_logo', 'updateLogo')->name('update_logo');
                Route::post('/update-favicon', 'updateFavicon')->name('update_favicon');
                Route::get('/categories', 'categoriesPage')->name('categories');
            });
            Route::controller(PostController::class)->group(function () {
                Route::get('/post/new', 'addPost')->name('add_post');
                Route::post('/post/create', 'createPost')->name('create_post');
                Route::get('/posts', 'allPost')->name('posts');
                Route::get('/post/{id}/edit', 'editPost')->name('edit_post');
                Route::post('/post/update', 'updatePost')->name('update_post');
            });
            Route::controller(FacultyController::class)->group(function () {
                Route::get('/faculty/new', 'addFaculty')->name('add_faculty');
                Route::post('/faculty/create', 'createFaculty')->name('create_faculty');
                Route::get('/faculty', 'allFaculty')->name('faculty');
                Route::get('/faculty/{id}/edit', 'editFaculty')->name('edit_faculty');
                Route::post('/faculty/update', 'updateFaculty')->name('update_faculty');
            });
            Route::controller(AlbumController::class)->group(function () {
                Route::get('/album/new', 'addAlbum')->name('add_album');
                Route::post('/album/create', 'createAlbum')->name('create_album');
                Route::get('/album', 'allAlbum')->name('album');
                Route::get('/album/{id}/edit', 'editAlbum')->name('edit_album');
                Route::post('/album/update', 'updateAlbum')->name('update_album');
            });
            Route::controller(AlbumPhotoController::class)->group(function () {
                Route::get('/album/{album}/photos', 'listPhotos')->name('photos.list');
                Route::post('/album/{album}/photos', 'uploadPhoto')->name('photos.upload');
            });
            Route::controller(FacilitiesController::class)->group(function () {
                Route::get('/facilities/new', 'addFacility')->name('add_facility');
                Route::post('/facilities/create', 'createFacilities')->name('create_facilities');
                Route::get('/facilities', 'allFacilities')->name('facilities');
                Route::get('/facilities/{id}/edit', 'editFacility')->name('edit_facility');
                Route::post('/facilities/update', 'updateFacility')->name('update_facility');
            });

            Route::controller(FacilitiesPhotoController::class)->group(function () {
                Route::get('/facilities/{facilities}/photos', 'listFacilityPhotos')->name('facilityPhotos.list');
                Route::post('/facilities/{facilities}/photos', 'uploadFacilityPhotos')->name('facilityPhotos.upload');
            });

            Route::controller(OfficesManageController::class)->group(function () {
                Route::get('/offices/new', 'addOfficeDepartment')->name('add_office_department');
                Route::post('/offices/create', 'createOfficeDepartment')->name('create_office_department');
                Route::get('/offices', 'allOfficeDepartment')->name('office_department');
                Route::get('/offices/{id}/edit', 'editOfficeDepartment')->name('edit_office_department');
                Route::post('/offices/update', 'updateOfficeDepartment')->name('update_office_department');
                Route::get('/admin/offices/available', [OfficesManageController::class, 'getAvailableOffices'])->name('get_available_offices');
            });
            Route::controller(AuthorController::class)->group(function () {
                Route::get('/authors/new', 'addAuthor')->name('add_author');
                Route::post('/authors/create', 'createAuthor')->name('create_author');
                Route::get('/authors', 'allAuthors')->name('authors');
                Route::get('/authors/{id}/edit', 'editAuthor')->name('edit_author');
                Route::post('/authors/update', 'updateAuthor')->name('update_author');
            });
            Route::controller(CarouselImageController::class)->group(function () {
                Route::get('/carousel/photo', 'listCarouselPhoto')->name('carouselphoto.list');
                Route::post('/carousel/photo', 'uploadCarouselPhoto')->name('carouselphoto.upload');
            });
        });
    });
});
