<?php

use App\Http\Controllers\SubmissionController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\PostController;
use App\Http\Controllers\ContactMessageController;
use App\Http\Controllers\ResultController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\LessonNoteController;
use App\Http\Controllers\AssignmentController;
use App\Http\Controllers\DailyUpdateController;
use App\Http\Controllers\AnnouncementController;
use App\Http\Controllers\MessageController;
use App\Http\Controllers\NewsletterController;
use Illuminate\Support\Facades\Route;


// =========================================================
// PUBLIC ROUTES
// =========================================================

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


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


Route::get('/news/{slug}', [PostController::class, 'show'])
    ->name('news.show');


Route::post('/contact', [ContactMessageController::class, 'store'])
    ->name('contact.store');


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


// =========================================================
// AUTHENTICATION ROUTES
// =========================================================
//
// IMPORTANT:
// Authentication routes MUST come before the dynamic
// /{slug} route at the bottom of this file.
//

require __DIR__.'/auth.php';


// =========================================================
// AUTHENTICATED USER ROUTES
// =========================================================

Route::get('/dashboard', [DashboardController::class, 'index'])
    ->middleware(['auth', 'verified'])
    ->name('dashboard');


Route::middleware('auth')->group(function () {

    // =====================================================
    // PROFILE
    // =====================================================

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

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

    Route::delete('/profile', [ProfileController::class, 'destroy'])
        ->name('profile.destroy');


    // =====================================================
    // STUDENT PORTAL
    // =====================================================

    Route::get('/my-results', [ResultController::class, 'studentResults'])
        ->name('student.results');


    Route::get('/my-assignments', [AssignmentController::class, 'studentAssignments'])
        ->name('student.assignments');


    Route::post('/assignments/{assignment}/submit', [SubmissionController::class, 'store'])
        ->name('student.submit');


    Route::get('/my-fees', [PaymentController::class, 'studentFees'])
        ->name('student.fees');


    Route::post('/fees/pay', [PaymentController::class, 'pay'])
        ->name('student.pay');


    Route::get('/daily-updates', [DailyUpdateController::class, 'studentUpdates'])
        ->name('student.updates');


    Route::get('/messages', [MessageController::class, 'index'])
        ->name('messages.index');


    Route::post('/messages', [MessageController::class, 'store'])
        ->name('messages.store');


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


    // =====================================================
    // TEACHER ROUTES
    // =====================================================

    Route::middleware(['role:teacher'])
        ->prefix('teacher')
        ->name('teacher.')
        ->group(function () {

            Route::get('/dashboard', [DashboardController::class, 'teacher'])
                ->name('dashboard');


            Route::resource('lesson-notes', LessonNoteController::class);


            Route::resource('assignments', AssignmentController::class);


            Route::resource('daily-updates', DailyUpdateController::class);


            Route::resource('results', ResultController::class);


            Route::post('/messages/{student}', [MessageController::class, 'sendToParent'])
                ->name('message.parent');

        });

});


// =========================================================
// DYNAMIC CMS PAGE ROUTE
// =========================================================
//
// IMPORTANT:
// This MUST be the LAST route.
//
// It handles pages created from the Filament admin panel,
// such as:
//
// /about
// /contact
// /admissions
// /academics
//
// Do NOT put anything below this route.
//

Route::get('/{slug}', [PageController::class, 'show'])
    ->name('page.show');