<?php

use App\Http\Controllers\Admin\BannerController;
use App\Http\Controllers\Admin\BlogCategoryController;
use App\Http\Controllers\Admin\BlogController;
use App\Http\Controllers\Admin\CategoryController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\DeliveryInfoController;
use App\Http\Controllers\Admin\FaqController;
use App\Http\Controllers\Admin\LiveSaleController;
use App\Http\Controllers\Admin\OrderController;
use App\Http\Controllers\Admin\ProductController;
use App\Http\Controllers\Admin\ServiceController;
use App\Http\Controllers\Admin\SettingsController;
use Illuminate\Support\Facades\Route;

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

    Route::resource('categories', CategoryController::class);
    Route::patch('categories/{category}/toggle-status', [CategoryController::class, 'toggleStatus'])->name('categories.toggle-status');
    Route::resource('faqs', FaqController::class);
    Route::patch('faqs/{faq}/toggle-status', [FaqController::class, 'toggleStatus'])->name('faqs.toggle-status');
    Route::resource('products', ProductController::class);
    Route::patch('products/{product}/toggle-status', [ProductController::class, 'toggleStatus'])->name('products.toggle-status');
    Route::patch('products/{product}/toggle-featured', [ProductController::class, 'toggleFeatured'])->name('products.toggle-featured');
    Route::resource('orders', OrderController::class);
    Route::patch('orders/{order}/status', [OrderController::class, 'updateStatus'])->name('orders.update-status');
    Route::patch('orders/{order}/payment-status', [OrderController::class, 'updatePaymentStatus'])->name('orders.update-payment-status');
    Route::resource('blogs', BlogController::class);
    Route::resource('blog-categories', BlogCategoryController::class);

    // Banner routes
    Route::resource('banners', BannerController::class)->except(['show']);
    Route::patch('banners/{banner}/toggle-status', [BannerController::class, 'toggleStatus'])->name('banners.toggle-status');

    // Live Sale (Daily Flash Deal) routes
    Route::get('live-sales/import', [LiveSaleController::class, 'import'])->name('live-sales.import');
    Route::get('live-sales/products/search', [LiveSaleController::class, 'searchProducts'])->name('live-sales.products.search');
    Route::resource('live-sales', LiveSaleController::class)->except(['show']);
    Route::patch('live-sales/{liveSale}/toggle-status', [LiveSaleController::class, 'toggleStatus'])->name('live-sales.toggle-status');

    // Delivery Info routes
    Route::resource('delivery-info', DeliveryInfoController::class)->except(['show']);
    Route::patch('delivery-info/{deliveryInfo}/toggle-status', [DeliveryInfoController::class, 'toggleStatus'])->name('delivery-info.toggle-status');

    // Service routes
    Route::resource('services', ServiceController::class)->except(['show']);
    Route::get('services/{service}/category-overrides', [ServiceController::class, 'categoryOverrides'])->name('services.category-overrides');
    Route::post('services/{service}/category-overrides', [ServiceController::class, 'upsertCategoryOverride'])->name('services.category-overrides.store');
    Route::delete('services/{service}/category-overrides/{categoryOverride}', [ServiceController::class, 'destroyCategoryOverride'])->name('services.category-overrides.destroy');
    Route::get('services/{service}/product-links', [ServiceController::class, 'productLinks'])->name('services.product-links');
    Route::post('services/{service}/product-links', [ServiceController::class, 'upsertProductLink'])->name('services.product-links.store');
    Route::patch('services/{service}/product-links/{productLink}/toggle', [ServiceController::class, 'toggleProductLink'])->name('services.product-links.toggle');
    Route::delete('services/{service}/product-links/{productLink}', [ServiceController::class, 'destroyProductLink'])->name('services.product-links.destroy');

    // Settings routes
    Route::get('settings', [SettingsController::class, 'index'])->name('settings.index');
    Route::put('settings', [SettingsController::class, 'update'])->name('settings.update');
    Route::post('settings/clear-cache', [SettingsController::class, 'clearCache'])->name('settings.clear-cache');

    // Admin password change routes
    Route::get('change-password', [App\Http\Controllers\Auth\PasswordChangeController::class, 'showAdminForm'])->name('password.change');
    Route::post('change-password', [App\Http\Controllers\Auth\PasswordChangeController::class, 'updateAdminPassword'])->name('password.update');
});
