<?php

use App\Http\Controllers\Student\CourseController;
use App\Http\Controllers\Student\DashboardController;
use App\Http\Controllers\Student\NotificationController;
use App\Http\Controllers\Student\ProfileController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth', 'customer'])->prefix('student')->name('student.')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

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

    // Courses (Moved index to dashboard, kept show for player)
    Route::get('/courses/{course:slug}', [CourseController::class, 'show'])->name('courses.show');
    Route::post('/courses/{course}/lessons/{lesson}/complete', [CourseController::class, 'markLessonAsComplete'])->name('courses.lessons.complete');
    Route::post('/courses/{course}/lessons/{lesson}/recheck', [CourseController::class, 'requestRecheck'])->name('courses.lessons.recheck');
    Route::post('/courses/{course}/complete', [CourseController::class, 'markCourseAsCompleted'])->name('courses.complete');

    // Live Classes
    Route::get('/live-classes/{liveClass}/join', [App\Http\Controllers\Student\LiveClassController::class, 'join'])->name('live-classes.join');

    // Notifications
    Route::get('/notifications', [NotificationController::class, 'index'])->name('notifications.index');
    Route::get('/notifications/recent', [NotificationController::class, 'recent'])->name('notifications.recent');
    Route::post('/notifications/{id}/read', [NotificationController::class, 'markAsRead'])->name('notifications.read');
    Route::post('/notifications/read-all', [NotificationController::class, 'markAllAsRead'])->name('notifications.read_all');
    Route::delete('/notifications/{id}', [NotificationController::class, 'destroy'])->name('notifications.destroy');

    // Certificates
    Route::get('/certificates', [App\Http\Controllers\Student\CertificateController::class, 'index'])->name('certificates.index');
    Route::get('/certificates/{certificate}/download', [App\Http\Controllers\Student\CertificateController::class, 'download'])->name('certificates.download');

    // Checkout
    Route::get('/checkout/callback', [App\Http\Controllers\Student\CheckoutController::class, 'callback'])->name('checkout.callback');
    Route::get('/checkout/{course:slug}', [App\Http\Controllers\Student\CheckoutController::class, 'show'])->name('checkout.show');
    Route::post('/checkout/{course}', [App\Http\Controllers\Student\CheckoutController::class, 'store'])->name('checkout.store');

    // Order History
    Route::get('/orders', [App\Http\Controllers\Student\OrderController::class, 'index'])->name('orders.index');
    Route::get('/orders/{order}', [App\Http\Controllers\Student\OrderController::class, 'show'])->name('orders.show');
    Route::get('/orders/{order}/invoice', [App\Http\Controllers\Student\OrderController::class, 'downloadInvoice'])->name('orders.invoice');

    // Announcements
    Route::get('/announcements', [\App\Http\Controllers\Student\AnnouncementController::class, 'index'])->name('announcements.index');
    Route::get('/announcements/{announcement}', [\App\Http\Controllers\Student\AnnouncementController::class, 'show'])->name('announcements.show');
    Route::post('/announcements/{announcement}/read', [\App\Http\Controllers\Student\AnnouncementController::class, 'markAsRead'])->name('announcements.read');
});
