<?php

use App\Http\Controllers\Admin\AuditLogController;
use App\Http\Controllers\Admin\CertificateController;
use App\Http\Controllers\Admin\CollegeController;
use App\Http\Controllers\Admin\CourseController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\StudentController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\PublicVerificationController;
use App\Http\Middleware\SuperAdminMiddleware;
use Illuminate\Support\Facades\Route;

// Public Routes
Route::get('/', function () {
    return redirect()->route('login');
});

Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
Route::post('/login', [LoginController::class, 'login']);
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');

// Public Authenticity QR Verification
Route::get('/verify/{uuid}', [PublicVerificationController::class, 'verify'])->name('public.verify');
Route::get('/verify/{uuid}/download', [PublicVerificationController::class, 'downloadPdf'])->name('public.verify.download');

// Admin Panel Routes (Protected by Auth)
Route::middleware(['auth'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

    // Colleges
    Route::resource('colleges', CollegeController::class);
    Route::post('colleges-inline', [CollegeController::class, 'storeInline'])->name('colleges.store_inline');

    // Courses
    Route::resource('courses', CourseController::class);
    Route::post('courses-inline', [CourseController::class, 'storeInline'])->name('courses.store_inline');

    // Students
    Route::resource('students', StudentController::class);
    Route::get('students-export/csv', [StudentController::class, 'exportCsv'])->name('students.export_csv');
    Route::post('students-import/csv', [StudentController::class, 'importCsv'])->name('students.import_csv');

    // Certificates
    Route::resource('certificates', CertificateController::class);
    Route::get('certificates/{certificate}/download-pdf', [CertificateController::class, 'downloadPdf'])->name('certificates.download_pdf');
    Route::post('certificates/{certificate}/resend-email', [CertificateController::class, 'resendEmail'])->name('certificates.resend_email');
    Route::post('certificates/{certificate}/revoke', [CertificateController::class, 'revoke'])->name('certificates.revoke');

    // Super Admin Only Routes
    Route::middleware([SuperAdminMiddleware::class])->group(function () {
        Route::resource('users', UserController::class);
        Route::get('audit-logs', [AuditLogController::class, 'index'])->name('audit_logs.index');
    });
});
