<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\BookingController;
use App\Http\Controllers\VehicleController;
use App\Http\Controllers\QAController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\FleetController;
use App\Http\Controllers\Admin\GalleryController;
use App\Http\Controllers\Admin\BlogController;
use App\Http\Controllers\Admin\BookingController as AdminBookingController;
use App\Http\Controllers\Admin\MessageController;
use App\Http\Controllers\Admin\NewsletterController;

// Main pages
Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/about', [HomeController::class, 'about'])->name('about');
Route::get('/fleet', [HomeController::class, 'fleet'])->name('fleet');
Route::get('/services', [HomeController::class, 'services'])->name('services');
Route::get('/gallery', [HomeController::class, 'gallery'])->name('gallery');
Route::get('/blog', [HomeController::class, 'blog'])->name('blog');
Route::get('/contact', [HomeController::class, 'contact'])->name('contact');
Route::post('/contact', [HomeController::class, 'sendContact'])->name('contact.send');
Route::get('/qa', [QAController::class, 'index'])->name('qa');

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

// Booking routes
Route::get('/book', [BookingController::class, 'index'])->name('bookings.index');
Route::post('/book', [BookingController::class, 'store'])->name('bookings.store');

// Vehicle routes (for future admin functionality)
Route::resource('vehicles', VehicleController::class);

// Sitemap route
Route::get('/sitemap.xml', function() {
    return response()->file(public_path('sitemap.xml'));
});

// Admin Routes
Route::prefix('admin')->name('admin.')->group(function () {
    // Admin login
    Route::get('/login', [AdminController::class, 'showLogin'])->name('login');
    Route::post('/login', [AdminController::class, 'login'])->name('login.post');
    Route::post('/logout', [AdminController::class, 'logout'])->name('logout');

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

        // Fleet management
        Route::resource('fleet', FleetController::class);

        // Gallery management
        Route::resource('gallery', GalleryController::class);

        // Blog management
        Route::resource('blog', BlogController::class);

        // Booking management
        Route::resource('bookings', AdminBookingController::class);
        Route::patch('/bookings/{booking}/status', [AdminBookingController::class, 'updateStatus'])->name('bookings.status');

        // Messages management
        Route::resource('messages', MessageController::class);
        Route::patch('/messages/{message}/status', [MessageController::class, 'updateStatus'])->name('messages.status');

        // Newsletter management
        Route::resource('newsletter', NewsletterController::class);
        Route::post('/newsletter/send', [NewsletterController::class, 'sendNewsletter'])->name('newsletter.send');
    });
});
