<?php

use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;

Route::get('/', [\App\Http\Controllers\FrontController::class, 'index'])->name('home');
Route::get('/product/{product:slug}', [\App\Http\Controllers\FrontController::class, 'show'])->name('product.show');
Route::get('/page/{slug}', [\App\Http\Controllers\FrontController::class, 'page'])->name('page.show');
Route::get('/api/page/{slug}', [\App\Http\Controllers\FrontController::class, 'pageJson'])->name('page.json');
Route::get('/sitemap.xml', [\App\Http\Controllers\FrontController::class, 'sitemap'])->name('sitemap');

Route::get('/checkout/{product:slug}', [\App\Http\Controllers\CheckoutController::class, 'index'])->name('checkout.index');
Route::post('/checkout/{product}', [\App\Http\Controllers\CheckoutController::class, 'process'])
    ->middleware('throttle:10,1')
    ->name('checkout.process');

Route::middleware(['auth', 'verified'])->group(function () {
    Route::get('/checkout/success/{order}', [\App\Http\Controllers\CheckoutController::class, 'success'])->name('checkout.success');
});

Route::get('/dashboard', [\App\Http\Controllers\DashboardController::class, 'index'])->middleware(['auth', 'verified'])->name('dashboard');
Route::get('/dashboard/order/{order:order_code}', [\App\Http\Controllers\DashboardController::class, 'show'])->middleware(['auth', 'verified'])->name('dashboard.order.show');

Route::middleware('auth')->group(function () {
    Route::get('/download/{order}', [\App\Http\Controllers\DownloadController::class, 'process'])
        ->middleware('check.order.paid')
        ->name('download');
    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');
});
require __DIR__.'/auth.php';

// Admin Routes
Route::prefix('admin')->name('admin.')->middleware(['auth', 'admin'])->group(function () {
    Route::get('/', function () {
        return view('admin.dashboard');
    })->name('dashboard');

    Route::resource('categories', \App\Http\Controllers\Admin\CategoryController::class);
    Route::resource('products', \App\Http\Controllers\Admin\ProductController::class);
    Route::resource('testimonials', \App\Http\Controllers\Admin\TestimonialController::class);
    Route::resource('orders', \App\Http\Controllers\Admin\OrderController::class);
    Route::resource('users', \App\Http\Controllers\Admin\UserController::class);
    Route::resource('banks', \App\Http\Controllers\Admin\BankAccountController::class);
    Route::get('settings/branding-app', [\App\Http\Controllers\Admin\SettingController::class, 'branding'])->name('settings.branding');
    Route::put('settings/branding-app', [\App\Http\Controllers\Admin\SettingController::class, 'storeBranding'])->name('settings.branding.store');
    Route::get('settings/footer', [\App\Http\Controllers\Admin\SettingController::class, 'footer'])->name('settings.footer');
    Route::put('settings/footer', [\App\Http\Controllers\Admin\SettingController::class, 'storeFooter'])->name('settings.footer.store');
    Route::get('settings/hero', [\App\Http\Controllers\Admin\SettingController::class, 'hero'])->name('settings.hero');
    Route::put('settings/hero', [\App\Http\Controllers\Admin\SettingController::class, 'storeHero'])->name('settings.hero.store');
    Route::get('settings/video', [\App\Http\Controllers\Admin\VideoController::class, 'index'])->name('settings.video');
    Route::post('settings/video', [\App\Http\Controllers\Admin\VideoController::class, 'storeSettings'])->name('settings.video.store');
    Route::post('videos', [\App\Http\Controllers\Admin\VideoController::class, 'store'])->name('videos.store');
    Route::put('videos/{video}', [\App\Http\Controllers\Admin\VideoController::class, 'update'])->name('videos.update');
    Route::delete('videos/{video}', [\App\Http\Controllers\Admin\VideoController::class, 'destroy'])->name('videos.destroy');
    Route::resource('settings', \App\Http\Controllers\Admin\SettingController::class)->only(['index', 'store']);
    Route::resource('pages', \App\Http\Controllers\Admin\PageController::class);

    // Maintenance
    Route::get('maintenance', [\App\Http\Controllers\Admin\MaintenanceController::class, 'index'])->name('maintenance.index');
    Route::post('maintenance/backup', [\App\Http\Controllers\Admin\MaintenanceController::class, 'backupDatabase'])->name('maintenance.backup');
    Route::get('maintenance/download', [\App\Http\Controllers\Admin\MaintenanceController::class, 'downloadBackup'])->name('maintenance.download');
    Route::post('maintenance/optimize', [\App\Http\Controllers\Admin\MaintenanceController::class, 'optimize'])->name('maintenance.optimize');
    Route::post('maintenance/clear', [\App\Http\Controllers\Admin\MaintenanceController::class, 'clearCache'])->name('maintenance.clear');

    // Themes
    Route::get('themes', [\App\Http\Controllers\Admin\ThemeController::class, 'index'])->name('themes.index');
    Route::post('themes', [\App\Http\Controllers\Admin\ThemeController::class, 'update'])->name('themes.update');
});
