<?php

use App\Http\Controllers\Admin\AdministratorController;
use App\Http\Controllers\Admin\ContactMessageController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\EmailServiceController;
use App\Http\Controllers\Admin\LoginController;
use App\Http\Controllers\Admin\SettingsController;
use App\Http\Controllers\Admin\ShipmentController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\TrackingController;
use App\Http\Middleware\EnsureAdminIsActive;
use Illuminate\Support\Facades\Route;

Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/about', [PageController::class, 'about'])->name('about');
Route::get('/services', [PageController::class, 'services'])->name('services');
Route::get('/services/{slug}', [PageController::class, 'service'])->name('services.show');
Route::get('/tracking', [TrackingController::class, 'index'])->name('tracking');
Route::get('/tracking/{code}/invoice', [TrackingController::class, 'invoice'])->name('tracking.invoice');
Route::get('/contact', [ContactController::class, 'index'])->name('contact');
Route::post('/contact', [ContactController::class, 'store'])->name('contact.store');

Route::prefix('admin')->name('admin.')->group(function () {
    Route::middleware('guest')->group(function () {
        Route::get('/login', [LoginController::class, 'show'])->name('login');
        Route::post('/login', [LoginController::class, 'login'])->name('login.attempt');
        Route::get('/forgot-password', [LoginController::class, 'forgot'])->name('password.request');
        Route::post('/forgot-password', [LoginController::class, 'sendReset'])->name('password.email');
        Route::get('/reset-password/{token}', [LoginController::class, 'resetForm'])->name('password.reset');
        Route::post('/reset-password', [LoginController::class, 'reset'])->name('password.update');
    });

    Route::middleware(['auth', EnsureAdminIsActive::class])->group(function () {
        Route::post('/logout', [LoginController::class, 'logout'])->name('logout');
        Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
        Route::resource('shipments', ShipmentController::class);
        Route::post('shipments/{shipment}/events', [ShipmentController::class, 'storeEvent'])->name('shipments.events.store');
        Route::get('email', [EmailServiceController::class, 'create'])->name('email.create');
        Route::post('email', [EmailServiceController::class, 'send'])->name('email.send');
        Route::get('messages', [ContactMessageController::class, 'index'])->name('messages.index');
        Route::get('messages/{message}', [ContactMessageController::class, 'show'])->name('messages.show');
        Route::delete('messages/{message}', [ContactMessageController::class, 'destroy'])->name('messages.destroy');
        Route::get('administrators', [AdministratorController::class, 'index'])->name('administrators.index');
        Route::get('administrators/create', [AdministratorController::class, 'create'])->name('administrators.create');
        Route::post('administrators', [AdministratorController::class, 'store'])->name('administrators.store');
        Route::get('administrators/{administrator}/edit', [AdministratorController::class, 'edit'])->name('administrators.edit');
        Route::put('administrators/{administrator}', [AdministratorController::class, 'update'])->name('administrators.update');
        Route::delete('administrators/{administrator}', [AdministratorController::class, 'destroy'])->name('administrators.destroy');
        Route::post('administrators/{administrator}/block', [AdministratorController::class, 'toggleBlock'])->name('administrators.block');
        Route::post('administrators/{administrator}/reset-password', [AdministratorController::class, 'resetPassword'])->name('administrators.reset');
        Route::get('settings', [SettingsController::class, 'index'])->name('settings.index');
        Route::post('settings', [SettingsController::class, 'update'])->name('settings.update');
    });
});
