<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\CMSController;
use App\Http\Controllers\Admin\PdfController;
use App\Http\Controllers\Admin\AdminController;
use App\Http\Controllers\MaintenanceController;
use App\Http\Controllers\Admin\ApplicationController;
use App\Http\Controllers\Frontend\FrontendController;

Route::controller(FrontendController::class)->group(function () {
    Route::get('/', 'index')->name('/');
    Route::get('/search-result', 'searchResult')->name('front.search-result');
});
Route::post('/find-reservation', [ApplicationController::class, 'findReservation'])
    ->name('reservation.find');

Route::get('/reservation-result/{passenger}', [ApplicationController::class, 'reservationResult'])
    ->name('reservation.result');

Route::post('/send-itinerary-email',
    [ApplicationController::class, 'sendItineraryEmail']
)->name('itinerary.email.send');

Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified',])->group(function () {
    Route::get('/dashboard', [CMSController::class, 'dashboard'])->name('dashboard');
    Route::get('/optimize:clear', [MaintenanceController::class, 'optimizeClear']);
    Route::get('/storage:link', [MaintenanceController::class, 'storageLink']);

    Route::middleware(['super_admin'])->group(function () {
        Route::controller(AdminController::class)->prefix('/admin')->name('admin.')->group(function () {
            Route::get('/role/{id}/{newRole}', 'role')->name('role');
            Route::get('/manage-admin', 'manageAdmin')->name('manage_admin');
            Route::get('/pending-user', 'pendingUser')->name('pending_user');
            Route::get('/admin-user', 'adminUser')->name('admin_user');
            Route::get('/super-admin-user', 'superAdminUser')->name('super_admin_user');
            Route::delete('/delete-admin/{id}', 'deleteAdmin')->name('delete_admin');
            Route::get('/edit-admin/{id}', 'editAdmin')->name('edit_admin');
            Route::post('/update-user-name-by-admin', 'updateUserNameByAdmin')->name('update_user_name_by_admin');
            Route::post('/update-user-email-by-admin', 'updateUserEmailByAdmin')->name('update_user_email_by_admin');
            Route::post('/update-user-photo-by-admin', 'updateUserPhotoByAdmin')->name('update_user_photo_by_admin');
            Route::post('/update-user-password-by-admin', 'updateUserPasswordByAdmin')->name('update_user_password_by_admin');
            Route::post('/update-user-phone-by-admin', 'updateUserPhoneByAdmin')->name('update_user_phone_by_admin');
        });
        Route::controller(CMSController::class)->prefix('/admin')->group(function () {
            Route::get('/manage-visa-application', 'manageVisaApplication')->name('manage_visa_application');
        });
        Route::get('/admin/application/{id}/edit-status', [CMSController::class, 'editStatus'])->name('application.edit.status');
        Route::post('/admin/application/{id}/update-status', [CMSController::class, 'updateStatus'])->name('application.update.status');

        Route::controller(CMSController::class)->prefix('/admin')->group(function () {
            Route::get('/add-passenger', 'addPassenger')->name('passenger.create');
            Route::post('/save-passenger', 'savePassenger')->name('passenger.store');
            Route::get('/passengers', 'listPassenger')->name('passenger.index');
            Route::get('/passenger/{id}/edit', 'editPassenger')->name('passenger.edit');
            Route::post('/passenger/{id}/update', 'updatePassenger')->name('passenger.update');
            Route::delete('/passenger/{id}', 'deletePassenger')->name('passenger.delete');

            Route::get('/add-airline-company', 'addAirlineCompany')->name('airline.company.create');
            Route::post('/save-airline-company', 'saveAirlineCompany')->name('airline.company.store');
            Route::get('/airline-company-list', 'listAirlineCompany')->name('airline.company.index');
            Route::get('/airline-company/{id}/edit', 'editAirlineCompany')->name('airline.company.edit');
            Route::post('/airline-company/{id}/update', 'updateAirlineCompany')->name('airline.company.update');
            Route::delete('/airline-company/{id}', 'deleteAirlineCompany')->name('airline.company.delete');

            Route::get('/add-airport', 'addAirport')->name('airport.create');
            Route::post('/save-airport', 'saveAirport')->name('airport.store');
            Route::get('/airports', 'listAirport')->name('airport.index');
            Route::get('/airport/{id}/edit', 'editAirport')->name('airport.edit');
            Route::post('/airport/{id}/update', 'updateAirport')->name('airport.update');
            Route::delete('/airport/{id}', 'deleteAirport')->name('airport.delete');
        });
        Route::controller(ApplicationController::class)->prefix('/admin')->group(function () {
            Route::get('/add-trip', 'addTrip')->name('trip.create');
            Route::post('/save-trip', 'saveTrip')->name('trip.store');
            Route::get('/trips', 'listTrip')->name('trip.index');
            Route::get('/trip/{id}/edit', 'editTrip')->name('trip.edit');
            Route::post('/trip/{id}/update', 'updateTrip')->name('trip.update');
            Route::delete('/trip/{id}', 'deleteTrip')->name('trip.delete');
            Route::post('/trip/{id}/change-status', 'changeTripStatus')->name('trip.change.status');
        });
    });
});