<?php

use App\Http\Controllers\AdmissionGuideController;
use App\Http\Controllers\BlogController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\CountryController;
use App\Http\Controllers\ExamController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ProgramController;
use App\Http\Controllers\ScholarshipController;
use App\Http\Controllers\Student\ApplicationController;
use App\Http\Controllers\Student\ApplicationWizardController;
use App\Http\Controllers\Student\DashboardController;
use App\Http\Controllers\Student\DocumentController;
use App\Http\Controllers\Student\ProfileController;
use App\Http\Controllers\UniversityController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Public Routes (No authentication required)
|--------------------------------------------------------------------------
*/

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

// Scholarships
Route::prefix('scholarships')->name('scholarships.')->group(function () {
    Route::get('/', [ScholarshipController::class, 'index'])->name('index');
    Route::get('/{slug}', [ScholarshipController::class, 'show'])->name('show');
});

// Programs
Route::prefix('programs')->name('programs.')->group(function () {
    Route::get('/', [ProgramController::class, 'index'])->name('index');
    Route::get('/{program}', [ProgramController::class, 'show'])->name('show');
});

// Countries
Route::prefix('countries')->name('countries.')->group(function () {
    Route::get('/', [CountryController::class, 'index'])->name('index');
    Route::get('/{country:slug}', [CountryController::class, 'show'])->name('show');
});

// Exams
Route::prefix('exams')->name('exams.')->group(function () {
    Route::get('/', [ExamController::class, 'index'])->name('index');
    Route::get('/{exam:slug}', [ExamController::class, 'show'])->name('show');
});

// Universities
Route::prefix('universities')->name('universities.')->group(function () {
    Route::get('/', [UniversityController::class, 'index'])->name('index');
    Route::get('/{slug}', [UniversityController::class, 'show'])->name('show');
});

// Admission Guides
Route::prefix('admission-guides')->name('admission-guides.')->group(function () {
    Route::get('/', [AdmissionGuideController::class, 'index'])->name('index');
    Route::get('/{slug}', [AdmissionGuideController::class, 'show'])->name('show');
    Route::get('/{slug}/download-checklist', [AdmissionGuideController::class, 'downloadChecklist'])->name('download');
});

// Blog
Route::prefix('blog')->name('blog.')->group(function () {
    Route::get('/', [BlogController::class, 'index'])->name('index');
    Route::get('/{slug}', [BlogController::class, 'show'])->name('show');
});

// Contact & Static Pages
Route::get('/contact', [ContactController::class, 'showContact'])->name('contact');
Route::post('/contact', [ContactController::class, 'submit'])->name('contact.submit');
Route::get('/search', [ContactController::class, 'search'])->name('search');
Route::get('/pages/about', [ContactController::class, 'showAbout'])->name('about');
Route::get('/pages/faq', [ContactController::class, 'showFaq'])->name('faq');

// Newsletter
Route::post('/newsletter', [ContactController::class, 'subscribeToNewsletter'])->name('newsletter.subscribe');

/*
|--------------------------------------------------------------------------
| Authenticated Routes (Student Portal)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'verified'])->group(function () {
    // Dashboard
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
});
Route::middleware(['auth', 'verified'])->prefix('portal')->name('portal.')->group(function () {

    // Dashboard

    // Profile management
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile');
    Route::put('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::put('/profile/password', [ProfileController::class, 'updatePassword'])->name('profile.password');

    // Applications
    Route::get('/applications', [ApplicationController::class, 'index'])->name('applications');
    Route::get('/apply/{program?}', [ApplicationWizardController::class, 'show'])->name('apply');
    Route::post('/apply/{program?}', [ApplicationWizardController::class, 'submit'])->name('apply.submit');

    // Documents
    Route::get('/documents', [DocumentController::class, 'index'])->name('documents');
    Route::post('/documents', [DocumentController::class, 'upload'])->name('documents.upload');
    Route::delete('/documents/{document}', [DocumentController::class, 'destroy'])->name('documents.destroy');
});

/*
|--------------------------------------------------------------------------
| Include Settings Routes
|--------------------------------------------------------------------------
*/

require __DIR__.'/settings.php';
