<?php

use App\Http\Controllers\InstallController;
use App\Http\Controllers\LandingController;
use App\Http\Controllers\SuperAdminController;
use App\Http\Controllers\VendorWebController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

// 0. Server Installation Wizard (/install)
Route::prefix('install')->group(function () {
    Route::get('/', [InstallController::class, 'welcome'])->name('install.welcome');
    Route::get('/requirements', [InstallController::class, 'requirements'])->name('install.requirements');
    Route::get('/database', [InstallController::class, 'database'])->name('install.database');
    Route::post('/database/test', [InstallController::class, 'testDb'])->name('install.database.test');
    Route::get('/admin', [InstallController::class, 'admin'])->name('install.admin');
    Route::post('/process', [InstallController::class, 'processInstall'])->name('install.process');
    Route::get('/complete', [InstallController::class, 'complete'])->name('install.complete');
});

// 1. Public Landing Website & Static Pages
Route::get('/', [LandingController::class, 'index'])->name('home');
Route::get('/privacy-policy', [LandingController::class, 'privacy'])->name('privacy');
Route::get('/terms-and-conditions', [LandingController::class, 'terms'])->name('terms');
Route::get('/about-us', [LandingController::class, 'about'])->name('about');
Route::get('/contact-us', [LandingController::class, 'contact'])->name('contact');

// 2. SuperAdmin Web Panel Routes (/admin)
Route::prefix('admin')->group(function () {
    Route::get('/login', [SuperAdminController::class, 'showLogin'])->name('admin.login');
    Route::post('/login', [SuperAdminController::class, 'login'])->name('admin.login.post');

    Route::middleware(['auth', 'role:superadmin'])->group(function () {
        Route::get('/dashboard', [SuperAdminController::class, 'dashboard'])->name('admin.dashboard');
        Route::get('/vendors', [SuperAdminController::class, 'vendors'])->name('admin.vendors');
        Route::post('/vendors', [SuperAdminController::class, 'storeVendor'])->name('admin.vendors.store');
        Route::post('/vendors/{id}/toggle-status', [SuperAdminController::class, 'toggleVendorStatus'])->name('admin.vendors.toggle');
        Route::get('/packages', [SuperAdminController::class, 'packages'])->name('admin.packages');
        Route::post('/packages', [SuperAdminController::class, 'storePackage'])->name('admin.packages.store');
        Route::get('/transactions', [SuperAdminController::class, 'transactions'])->name('admin.transactions');
        Route::get('/settings', [SuperAdminController::class, 'settings'])->name('admin.settings');
        Route::post('/settings', [SuperAdminController::class, 'updateSettings'])->name('admin.settings.update');
        Route::post('/settings/profile', [SuperAdminController::class, 'updateAdminProfile'])->name('admin.settings.profile');
        Route::post('/settings/notify', [SuperAdminController::class, 'sendTestNotification'])->name('admin.settings.notify');
        Route::post('/logout', [SuperAdminController::class, 'logout'])->name('admin.logout');
    });
});

// 3. Vendor Admin Web Portal Routes (/vendor)
Route::prefix('vendor')->group(function () {
    Route::get('/login', [VendorWebController::class, 'showLogin'])->name('vendor.login');
    Route::post('/login', [VendorWebController::class, 'login'])->name('vendor.login.post');

    Route::middleware(['auth', 'role:vendor'])->group(function () {
        Route::get('/dashboard', [VendorWebController::class, 'dashboard'])->name('vendor.dashboard');
        Route::get('/frames', [VendorWebController::class, 'frames'])->name('vendor.frames');
        Route::post('/frames', [VendorWebController::class, 'storeFrame'])->name('vendor.frames.store');
        Route::delete('/frames/{id}', [VendorWebController::class, 'deleteFrame'])->name('vendor.frames.delete');

        Route::get('/lenses', [VendorWebController::class, 'lenses'])->name('vendor.lenses');
        Route::post('/lenses', [VendorWebController::class, 'storeLens'])->name('vendor.lenses.store');
        Route::delete('/lenses/{id}', [VendorWebController::class, 'deleteLens'])->name('vendor.lenses.delete');

        Route::get('/banners', [VendorWebController::class, 'banners'])->name('vendor.banners');
        Route::post('/banners', [VendorWebController::class, 'storeBanner'])->name('vendor.banners.store');
        Route::delete('/banners/{id}', [VendorWebController::class, 'deleteBanner'])->name('vendor.banners.delete');

        Route::get('/offers', [VendorWebController::class, 'offers'])->name('vendor.offers');
        Route::post('/offers', [VendorWebController::class, 'storeOffer'])->name('vendor.offers.store');
        Route::delete('/offers/{id}', [VendorWebController::class, 'deleteOffer'])->name('vendor.offers.delete');

        Route::get('/events', [VendorWebController::class, 'events'])->name('vendor.events');
        Route::post('/events', [VendorWebController::class, 'storeEvent'])->name('vendor.events.store');
        Route::delete('/events/{id}', [VendorWebController::class, 'deleteEvent'])->name('vendor.events.delete');

        Route::get('/notifications', [VendorWebController::class, 'notifications'])->name('vendor.notifications');
        Route::post('/notifications', [VendorWebController::class, 'sendNotification'])->name('vendor.notifications.send');

        Route::get('/cutout-tool', [VendorWebController::class, 'cutoutTool'])->name('vendor.cutout');
        Route::get('/subscription', [VendorWebController::class, 'subscription'])->name('vendor.subscription');
        Route::get('/profile', [VendorWebController::class, 'profile'])->name('vendor.profile');
        Route::post('/profile', [VendorWebController::class, 'updateProfile'])->name('vendor.profile.update');

        Route::get('/customers', [VendorWebController::class, 'customers'])->name('vendor.customers');
        Route::get('/orders', [VendorWebController::class, 'orders'])->name('vendor.orders');
        Route::post('/orders', [VendorWebController::class, 'storeOrder'])->name('vendor.orders.store');
        Route::patch('/orders/{id}', [VendorWebController::class, 'updateOrder'])->name('vendor.orders.update');
        Route::get('/stock', [VendorWebController::class, 'stock'])->name('vendor.stock');
        Route::patch('/stock/{type}/{id}', [VendorWebController::class, 'updateStock'])->name('vendor.stock.update');
        Route::post('/stock/{type}/{id}/toggle', [VendorWebController::class, 'toggleProduct'])->name('vendor.stock.toggle');
        Route::get('/bills', [VendorWebController::class, 'bills'])->name('vendor.bills');
        Route::get('/bills/{id}', [VendorWebController::class, 'bill'])->name('vendor.bills.show');
        Route::post('/logout', [VendorWebController::class, 'logout'])->name('vendor.logout');
    });
});
