<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\admin\Homecontroller;
use App\Http\Controllers\admin\UpdateStatusController;


use App\Http\Controllers\admin\CouponUpdateController;
use App\Http\Controllers\admin\TermsAndConditionsController;
use App\Http\Controllers\admin\BannerAdController;
use App\Http\Controllers\admin\Auth\AuthenticatedSessionController;
use App\Http\Controllers\admin\Auth\RegisteredUserController;

use App\Http\Controllers\admin\Auth\NewPasswordController;
use App\Http\Controllers\VendorController;
use App\Http\Controllers\PricingController;
use App\Http\Controllers\InventoryAndOrderController;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\BannerAdsController;
// routes/web.php

use App\Http\Controllers\SubscriptionPlanController;

use App\Http\Controllers\ContentController;
use App\Http\Controllers\TrainingModuleController;
use App\Http\Controllers\FaqController;
use App\Http\Controllers\ReviewController;
use App\Http\Controllers\QueryManagementController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\QueryController;
use App\Http\Controllers\CouponController as MyCouponController;
use App\Http\Controllers\CashCollectionManagementController;
use App\Http\Controllers\CashCollectionController;
use App\Http\Controllers\DriverController;
use App\Http\Controllers\DonationsController;

use App\Http\Controllers\VendorsController;

use App\Http\Controllers\LaundryItemController;

use App\Http\Controllers\VendorPaymentHistoryController;









// Web routes


/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

// Public Routes (Accessible to Everyone)
Route::get('/', function () {
    return auth()->check() ? redirect()->route('dashboard') : redirect()->route('login');
});
Route::fallback(function () {
    return view('welcome');
});
Route::get('login', [AuthenticatedSessionController::class, 'create'])->name('login');


Route::post('login', [AuthenticatedSessionController::class, 'store']);



Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])->name('password.reset');
Route::post('reset-password', [NewPasswordController::class, 'store'])->name('password.update');

Route::get('/test-email', function () {
    Mail::raw('This is a test email', function ($message) {
        $message->to('your_test_email@example.com')->subject('Test Email');
    });

    return 'Email sent';
});


// Protected Routes (Require Authentication)
Route::middleware(['auth'])->group(function () {
Route::get('/vendor-payment-histories', [VendorPaymentHistoryController::class, 'index'])->name('vendor-payment-histories.index');
Route::post('/vendor-payment-histories', [VendorPaymentHistoryController::class, 'store'])->name('vendor-payment-histories.store');
Route::delete('/vendor-payment-histories/{id}', [VendorPaymentHistoryController::class, 'destroy'])->name('vendor-payment-histories.destroy');
    Route::prefix('vendors')->group(function () {

    // Route to store a new vendor
    Route::post('/store', [VendorsController::class, 'storeVendor'])->name('vendors.store');
    
    // Route to update vendor opening hours
    Route::put('/{vendorId}/update-opening-hours', [VendorsController::class, 'updateOpeningHours'])->name('vendors.updateOpeningHours');
    
    // Route to import pricing data
    Route::post('/import', [VendorsController::class, 'import'])->name('vendors.import');
    
    // Route to get all filtered vendors
    Route::get('/filtered', [VendorsController::class, 'getFilteredVendors'])->name('vendors.getFiltered');
    
    // Route to get all services
    Route::get('/services', [VendorsController::class, 'getAllServices'])->name('vendors.getAllServices');
    
});

    Route::post('/drivers', [DriverController::class, 'store'])->name('drivers.store');
Route::resource('laundry-items', LaundryItemController::class);
Route::get('/donations', [DonationsController::class, 'index'])->name('donations.index');

Route::get('/drivers', [DriverController::class, 'index'])->name('drivers.index');
Route::put('/drivers/{driver}', [DriverController::class, 'update'])->name('drivers.update');
Route::delete('/drivers/{driver}', [DriverController::class, 'destroy'])->name('drivers.destroy');
Route::get('/cash-collection-history', [CashCollectionController::class, 'index'])->name('cashCollectionHistory.index');
Route::post('/delivery-agent-approval/{ID}/update-status', [Homecontroller::class, 'updateApprovalStatus'])->name('updateApprovalStatus');

Route::resource('cash_collections', CashCollectionManagementController::class);
Route::prefix('coupons')->group(function () {
    Route::get('/', [CouponController::class, 'index'])->name('coupons.index');          // List all coupons
    Route::post('/', [CouponController::class, 'store'])->name('coupons.store');          // Create a new coupon
    Route::get('/{id}/edit', [CouponController::class, 'edit'])->name('coupons.edit');    // Get a specific coupon for editing
    Route::put('/{id}', [CouponController::class, 'update'])->name('coupons.updateStatus');     // Update the coupon
    Route::delete('/{id}', [CouponController::class, 'destroy'])->name('coupons.destroy'); // Delete a coupon
});
Route::prefix('vendor')->group(function () {
    // Display inventory and orders
    Route::get('inventory', [InventoryAndOrderController::class, 'index'])->name('vendor.inventory.index');

    // Store a new inventory item
    Route::post('inventory', [InventoryAndOrderController::class, 'storeInventory'])->name('vendor.inventory.store');

    // Update an inventory item
    Route::put('inventory/{inventory}', [InventoryAndOrderController::class, 'updateInventory'])->name('vendor.inventory.update');

    // Delete an inventory item
    Route::delete('inventory/{inventory}', [InventoryAndOrderController::class, 'destroyInventory'])->name('vendor.inventory.destroy');

    // Store a new vendor order
    Route::post('order', [InventoryAndOrderController::class, 'storeOrder'])->name('vendor.order.store');

    // Delete a vendor order
    Route::delete('order/{order}', [InventoryAndOrderController::class, 'destroyOrder'])->name('vendor.order.destroy');
});
Route::prefix('querymanagement')->group(function () {
    // Route for storing a new query
   

    // Route for updating an existing query
    Route::put('/{id}', [QueryManagementController::class, 'update']);

    // Route for deleting a query
    Route::delete('/{id}', [QueryManagementController::class, 'destroy']);

    // Route for getting all queries
    Route::get('/', [QueryManagementController::class, 'index']);

    // Route for retrieving a specific query
    Route::get('/{id}', [QueryManagementController::class, 'show']);
});
Route::get('/query_management_business', [QueryController::class, 'index'])->name('queries.index');
Route::put('/queries/{id}', [QueryController::class, 'update'])->name('queries.update');
Route::delete('/queries/{id}', [QueryController::class, 'destroy'])->name('queries.destroy');
  Route::get('querymanagement', [QueryManagementController::class, 'index'])->name('querymanagement');
    Route::get('dashboard', [HomeController::class, 'dashboard'])->name('dashboard');
    Route::post('/pricing/update', [PricingController::class, 'updatePricingData'])->name('pricing.update');
Route::prefix('training')->group(function () {
    Route::get('/', [TrainingModuleController::class, 'index']); // List all training modules
    Route::post('/', [TrainingModuleController::class, 'store']); // Create a new training module
    Route::get('{id}', [TrainingModuleController::class, 'show']); // Show a specific training module
    Route::put('{id}', [TrainingModuleController::class, 'update']); // Update a specific training module
    Route::delete('{id}', [TrainingModuleController::class, 'destroy']); // Delete a specific training module
});
Route::resource('services', ServiceController::class);

Route::get('services', [ServiceController::class, 'index'])->name('services.index');
Route::get('/reviews', [ReviewController::class, 'indexAdmin'])->name('reviews');
Route::get('/FAQ_management', [FaqController::class, 'index'])->name('faqs.index');



// Route to store a new FAQ
Route::post('/FAQ_management', [FaqController::class, 'store'])->name('faqs.store');

// Route to show the edit form for an existing FAQ
Route::get('/FAQ_management/{id}/edit', [FaqController::class, 'edit'])->name('faqs.edit');

// Route to update an existing FAQ
Route::put('/FAQ_management/{id}', [FaqController::class, 'update'])->name('faqs.update');

// Route to delete an FAQ
Route::delete('/FAQ_management/{id}', [FaqController::class, 'destroy'])->name('faqs.destroy');

Route::get('/contents', [ContentController::class, 'index'])->name('contents.index');
Route::post('/contents', [ContentController::class, 'store'])->name('contents.store');
Route::get('/contents/{id}', [ContentController::class, 'show'])->name('contents.show');

Route::put('/contents/{id}', [ContentController::class, 'update'])->name('contents.update');
Route::delete('/contents/{id}', [ContentController::class, 'destroy'])->name('contents.destroy');
Route::prefix('bannerads')->group(function () {
    // Display the banner ads management view
    Route::get('/', [BannerAdsController::class, 'index'])->name('banners.index');

    // Store a new banner ad
    Route::post('/', [BannerAdsController::class, 'store'])->name('banners.store');

    // Display a specific banner ad
    Route::get('/{id}', [BannerAdsController::class, 'show'])->name('banners.show');

    // Update an existing banner ad
    Route::post('/{id}', [BannerAdsController::class, 'update'])->name('banners.update');

    // Delete a banner ad
    Route::delete('/{id}', [BannerAdsController::class, 'destroy'])->name('banners.destroy');

    // Get all active banner ads
    Route::get('/active', [BannerAdsController::class, 'getActiveAds'])->name('banners.active');
});
    Route::put('/vendors/{vendorId}/opening-hours', [VendorController::class, 'updateOpeningHours'])->name('updateOpeningHours');
    Route::put('/vendors/{vendorId}/services', [VendorController::class, 'updateServices'])->name('vendors.updateServices');
// Define the index route with a custom name
Route::get('subscription-plans', [SubscriptionPlanController::class, 'index'])->name('subscription.index');

// Define other routes using resource
Route::resource('subscription-plans', SubscriptionPlanController::class)->except(['index']);

    Route::get('/vendor/pricing', [PricingController::class, 'getAdminPricingData']);
   
   
    Route::get('/subscription', function () {
        return view('components.subscription');
    });
    Route::post('/import-pricing', [VendorController::class, 'import'])->name('import.pricing');
    Route::get('/Log_management', function () {
        return view('components.Log_Management');
    });
    Route::get('/training_module', function () {
        return view('components.training_module');
    });
    Route::get('sidemenu', [Homecontroller::class, 'sidemenu'])->name('sidemenu');

    Route::get('analystic_sales', [Homecontroller::class, 'analystic_sales'])->name('analystic_sales');

    Route::get('analystic_traffic', [Homecontroller::class, 'analystic_traffic'])->name('analystic_traffic');

    Route::get('analystic_products', [Homecontroller::class, 'analystic_products'])->name('analystic_products');

    Route::get('settings', [Homecontroller::class, 'settings'])->name('settings');
    Route::post('settings/add', [Homecontroller::class, 'staff_add']);



    Route::get('payment', [Homecontroller::class, 'payment'])->name('payment');
    Route::get('payment_details', [Homecontroller::class, 'payment_details'])->name('payment_details');

    Route::get('/orders_api', [Homecontroller::class, 'orders_api'])->name('orders_api');
    Route::get('/order_api', [Homecontroller::class, 'order_api'])->name('order_api');
    Route::get('/order_apis', [Homecontroller::class, 'order_apis'])->name('order_apis');
    Route::get('/fetch-orders', [Homecontroller::class, 'fetchOrders'])->name('fetch.orders');
    Route::get('/fetch-delivered-orders', [Homecontroller::class, 'fetchDeliveredOrders'])->name('fetch.delivered.orders');
    Route::get('orders', [Homecontroller::class, 'orders'])->name('orders');
    Route::get('/order/{id}', [Homecontroller::class, 'ordersShow'])->name('ordersShow');
    // Route::get('orderDetails/{id}',  [Homecontroller::class ,"orderDetails"])->name('orderDetails');
    // Route::get('/orderDetails/{id}', [Homecontroller::class, 'orderDetails'])->name('orderDetails');
    // Route::get('/orderdetails/{id}', [Homecontroller::class, 'show'])->name('orderDetails');
    Route::get('/orderDetails/{id}', [Homecontroller::class, 'showOrderDetails'])->name('orderDetails');

    Route::get('fetch_all_users', [Homecontroller::class, 'fetch_all_users'])->name('fetch_all_users');
    Route::get('user_management', [Homecontroller::class, 'user_management'])->name('user_management');
    Route::get('user_registration', [Homecontroller::class, 'user_registration'])->name('user_registration');
    Route::get('users_import', [Homecontroller::class, 'users_import'])->name('users_import');
    Route::get('usermanagement_userdetail/{id}', [Homecontroller::class, 'usermanagement_userdetail'])->name('usermanagement_userdetail');
    Route::get('user_details_page/{id}', [Homecontroller::class, 'user_details_page'])->name('user_details_page');
    Route::get('users_register/{id}', [Homecontroller::class, 'users_register'])->name('users_register');

    Route::post('/download-excel', [UserController::class, 'downloadExcel']);

    /* Vendor */
    /*  ======== */
    Route::get('/vendor/{ID}', [Homecontroller::class, 'getVendorDetails']);
    Route::get('fetch_all_vendors', [Homecontroller::class, 'fetch_all_vendors'])->name('fetch_all_vendors');
    Route::post('vendor-registration', [Homecontroller::class, 'registerVendor'])->name('vendor.registration');
    Route::get('vendors', [Homecontroller::class, 'vendors'])->name('vendors');
    Route::get('vendor_add/{id}', [Homecontroller::class, 'vendor_add'])->name('vendor_add');
    Route::get('Vendor_Approval_Request', [Homecontroller::class, 'Vendor_Approval_Request'])->name('Vendor_Approval_Request');
    Route::get('vendor_preview/{user_id}', [Homecontroller::class, 'vendor_preview'])->name('vendor_preview');
    Route::get('vendor_registration', [Homecontroller::class, 'vendor_registration'])->name('vendor_registration');
    Route::get('vendor_import', [Homecontroller::class, 'vendor_import'])->name('vendor_import');
    Route::get('vendor_approve_button/{id}', [Homecontroller::class, 'vendor_approve_button'])->name('vendor_approve_button');


    /* Delivery */
    /* ======== */
    Route::post('/delivery-agent/add', [Homecontroller::class, 'delivery_store']);
    Route::get('delivery_api', [Homecontroller::class, 'delivery_api'])->name('delivery_api');
    Route::get('delivery', [Homecontroller::class, 'delivery'])->name('delivery');
    Route::get('deliveryAgentProfile/{id}', [Homecontroller::class, 'deliveryAgentProfile'])->name('deliveryAgentProfile');
    Route::get('delivery_add', [Homecontroller::class, 'delivery_add'])->name('delivery_add');
    Route::get('delivery_import', [Homecontroller::class, 'delivery_import'])->name('delivery_import');
    Route::get('delivery_approve_request', [Homecontroller::class, 'delivery_approve_request'])->name('delivery_approve_request');
    Route::get('delivery_agent_approve_button/{id}', [Homecontroller::class, 'delivery_agent_approve_button'])->name('delivery_agent_approve_button');
  
    /* Query Management */
    /* ======== */
    Route::get('query_management', [Homecontroller::class, 'query_management'])->name('query_management');

    Route::patch('/query_management/updateStatus/{queryId}', [UpdateStatusController::class, 'updateStatus'])->name('updateStatus');
    Route::patch('/query_management/closeStatus/{closeStatusId}', [UpdateStatusController::class, 'closeStatus'])->name('closeStatus');
    Route::delete('/cleaneomain/query_management/deleteQuery/{id}', [UpdateStatusController::class, 'deleteQuery'])->name('deleteQuery');

    Route::get('service_management', [Homecontroller::class, 'service_management'])->name('service_management');

    Route::get('contentManagement', [Homecontroller::class, 'contentManagement'])->name('contentManagement');
    Route::get('/api/ads', [Homecontroller::class, 'getAds']);
    Route::get('/get-terms', [TermsAndConditionsController::class, 'getTerms']); // Fetch existing terms
    Route::post('/save-terms', [TermsAndConditionsController::class, 'saveTerms']); // Save or update terms
    Route::get('/get-privacy-policy', [TermsAndConditionsController::class, 'getPrivacyPolicy']); // Fetch existing data
    Route::post('/save-privacy-policy', [TermsAndConditionsController::class, 'savePrivacyPolicy']); // Save or update data
    Route::get('/get-content-policy', [TermsAndConditionsController::class, 'getContentPolicy']); // Fetch existing data
    Route::post('/save-content-policy', [TermsAndConditionsController::class, 'saveContentPolicy']); // Save or update data

    // Banner Ads
    Route::post('/bannerAds', [BannerAdController::class, 'createBannerAds']);
    Route::get('/get-advertisement/{id}', [BannerAdController::class, 'getAdvertisement']);
    // Route::put('/update-advertisement/{ID}', [BannerAdController::class, 'updateBannerAds']);
    Route::put('/update-advertisement/{id}', [BannerAdController::class, 'updateBannerAds']);
    Route::post('/update-ad-status', [BannerAdController::class, 'updateStatusAd']);
    Route::delete('/delete-ad/{id}', [BannerAdController::class, 'deleteAd'])->name('delete-ad');
});

?>
