<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes->get('/', 'Home::index');
$routes->get('products', 'Products::index');    // When someone visits /products via GET, it calls the index() method in Products controller
$routes->get('productDetails', 'ProductDetails::index'); 
$routes->get('productDetails/(:num)', 'ProductDetails::index/$1');

$routes->get('db', 'Db::index'); 

$routes->get('order-tracking', 'OrderTracking::index');
$routes->get('order-tracking/getStatus/(:num)', 'OrderTracking::getStatus/$1');


$routes->get('/delivery', 'Delivery::index');
$routes->get('/delivery/track/(:num)', 'Delivery::trackOrder/$1');
$routes->post('/delivery/updateLocation', 'Delivery::updateLocation');

$routes->get('delivery/track/(:num)', 'Delivery::track/$1');
$routes->post('delivery/updateStatus', 'Delivery::updateStatus');
$routes->get('deliveryController', 'DeliveryController::index');

$routes->get('deliveryController', 'DeliveryController::index');
$routes->get('deliveryController/view/(:num)', 'DeliveryController::view/$1');
$routes->post('deliveryController/updateStatus', 'DeliveryController::updateStatus');

$routes->post('payment/initiate', 'Payment::initiate');
$routes->post('payment/response', 'Payment::response');



$routes->get('getApartments', 'AuthController::getApartments');
$routes->post('saveApartment', 'AuthController::saveApartment');
$routes->get('getApartments', 'AuthController::getApartments');


$routes->get('product/(:num)', 'ProductDetails::index/$1');
$routes->post('ProductDetails/addToCart', 'ProductDetails::addToCart');



$routes->get('product/(:num)', 'ProductDetails::index/$1');
$routes->post('ProductDetails/addToCart', 'ProductDetails::addToCart');
$routes->get('order/cartCount', 'ProductDetails::cartCount');

$routes->post('ProductDetails/addToCart', 'ProductDetails::addToCart');



$routes->post('products/save', 'Products::save'); // When a POST request is made to /products/save, it calls the save() method
$routes->get('authController', 'AuthController::index');  

$routes->get('adDashboard', 'adDashboard::index');
$routes->post('adDashboard/refillStock/(:num)', 'adDashboard::refillStock/$1');

$routes->post('ProductDetails/addToCart', 'ProductDetails::addToCart');
$routes->get('order/cartCount', 'Order::cartCount');


$routes->get('productdetails/(:num)', 'ProductDetails::index/$1');
$routes->post('productdetails/addToCart', 'ProductDetails::addToCart');
$routes->get('productdetails/cartCount', 'ProductDetails::cartCount');


$routes->get('/', 'Login::index');
$routes->get('adDashboard', 'AdminDashboard::index'); // Dashboard route
$routes->get('products', 'AddProducts::index'); // Dashboard route
$routes->get('orders', 'Order::index'); // Dashboard route
$routes->get('products', 'AddProducts::index');
$routes->post('products/save', 'AddProducts::save');

$routes->get('AdminDashboard', 'AdminDashboard::index');
$routes->get('AdminDashboard/refillStock/(:num)', 'AdminDashboard::refillStock/$1');

$routes->get('AdminDashboard', 'AdminDashboard::index');
$routes->match(['get', 'post'], 'AdminDashboard/refillStock/(:num)', 'AdminDashboard::refillStock/$1');


$routes->match(['get', 'post'], 'AdminDashboard/refillStock/(:num)', 'AdminDashboard::refillStock/$1');

$routes->get('order', 'Order::index');
$routes->post('order/add-to-cart', 'Order::addToCart');
$routes->post('order/remove-from-cart', 'Order::removeFromCart');
$routes->get('order/clear-cart', 'Order::clearCart');

$routes->get('order/checkout', 'Order::checkout');
$routes->post('order/confirm', 'Order::confirmOrder');

$routes->get('order', 'Order::index');
$routes->get('order/category/(:num)', 'Order::category/$1');
$routes->post('order/confirmOrder', 'Order::confirmOrder');

$routes->get('order', 'Order::index');
$routes->post('order/confirmOrder', 'Order::confirmOrder');
$routes->post('order/paymentSuccess', 'Order::paymentSuccess');


$routes->get('products', 'Products::index');    // Show the add product page
$routes->post('products/save', 'Products::save'); // Handle form submission

 
$routes->get('/order', 'Order::index');
$routes->post('/order/addToCart', 'Order::addToCart');
$routes->get('/order/cart', 'Order::cart');
$routes->get('/order/removeFromCart/(:num)', 'Order::removeFromCart/$1');
$routes->post('order/addToCart', 'Order::addToCart');
$routes->get('order', 'Order::index');
$routes->post('order/addToCart', 'Order::addToCart');
$routes->get('order/cart', 'Order::cart');

$routes->get('orders', 'Order::index');
$routes->post('orders/addToCart', 'Order::addToCart');
$routes->get('orders/viewCart', 'Order::viewCart');
$routes->post('orders/confirmOrder', 'Order::confirmOrder');


$routes->get('orders', 'Order::index');               // To view products and add to cart
$routes->post('orders/addToCart', 'Order::addToCart');  // To add items to the cart
$routes->get('orders/viewCart', 'Order::viewCart');     // To view the cart
$routes->post('orders/confirmOrder', 'Order::confirmOrder'); // To confirm the order

$routes->get('orders/viewCart', 'Order::viewCart');

$routes->get('orders', 'Order::index');                // To view products and add to cart
$routes->post('orders/addToCart', 'Order::addToCart');   // To add items to the cart
$routes->get('orders/viewCart', 'Order::viewCart');      // To view the cart
$routes->post('orders/confirmOrder', 'Order::confirmOrder');  // To confirm the order



$routes->get('category', 'Category::index');
$routes->post('category/save', 'Category::save');

$routes->get('category', 'Category::index');
$routes->get('category/add', 'Category::add');
$routes->post('category/save', 'Category::save');
$routes->get('category/edit/(:num)', 'Category::edit/$1');
$routes->post('category/update/(:num)', 'Category::update/$1');
$routes->get('category/delete/(:num)', 'Category::delete/$1');

// Apartment Routes
$routes->get('apartment', 'Apartment::index');
$routes->get('apartment/add', 'Apartment::add');
$routes->post('apartment/save', 'Apartment::save');
$routes->get('apartment/edit/(:num)', 'Apartment::edit/$1');
$routes->post('apartment/update/(:num)', 'Apartment::update/$1');
$routes->get('apartment/delete/(:num)', 'Apartment::delete/$1');

$routes->get('order/fetchApartments', 'Order::fetchApartments');
$routes->get('apartments', 'Order::fetchApartments');



$routes->get('login', 'Login::index');
$routes->post('login/sendOtp', 'Login::sendOtp');
$routes->post('login/verifyOtp', 'Login::verifyOtp');

$routes->get('login', 'Login::index');
$routes->post('login/sendOtp', 'Login::sendOtp');
$routes->post('login/verifyOtp', 'Login::verifyOtp');
$routes->post('login/selectApartment', 'Login::selectApartment');
$routes->get('orders', 'Order::index'); // Your orders controller
$routes->get('order/getApartmentAddress', 'Order::getApartmentAddress');







$routes->get('login', 'AuthController::index');
$routes->post('sendOTP', 'AuthController::sendOTP');
$routes->post('verifyOTP', 'AuthController::verifyOTP');
$routes->get('logout', 'AuthController::logout');

// Protect order page
$routes->get('order', 'Order::index', ['filter' => 'auth']);

$routes->get('login', 'AuthController::index');

$routes->get('ecommerce/login', 'AuthController::index');

$routes->get('login', 'AuthController::index');
$routes->post('sendOTP', 'AuthController::sendOTP');
$routes->post('verifyOTP', 'AuthController::verifyOTP');
$routes->get('logout', 'AuthController::logout');
$routes->get('order', 'Order::index'); // Redirect page after login





$routes->get('login', 'AuthController::login');
$routes->post('sendOTP', 'AuthController::sendOTP');
$routes->post('verifyOTP', 'AuthController::verifyOTP');
$routes->get('logout', 'AuthController::logout');

// Protect order page
$routes->get('order', 'Order::index', ['filter' => 'auth']);


$routes->get('login', 'AuthController::index');
$routes->post('sendOTP', 'AuthController::sendOTP');
$routes->post('verifyOTP', 'AuthController::verifyOTP');
$routes->get('logout', 'AuthController::logout');

// Order page (protected)
$routes->get('order', 'Order::index', ['filter' => 'auth']); // use auth filter if needed


$routes->get('cart', 'Order::cart');           
$routes->get('order', 'Order::index');
$routes->post('order/addToCart', 'Order::addToCart');
$routes->get('order/cart', 'Order::cart');
$routes->get('order/remove/(:num)', 'Order::remove/$1');
$routes->get('order/getCartItems', 'Order::getCartItems');
$routes->post('order/removeItem/(:num)', 'Order::removeItem/$1');
$routes->post('order/placeOrder', 'Order::placeOrder');


$routes->get('order/getApartments', 'Order::getApartments');
$routes->get('order/getApartmentAddress/(:num)', 'Order::getApartmentAddress/$1');
$routes->get('order/getApartments', 'Order::getApartments');
$routes->get('order/getApartmentAddress/(:num)', 'Order::getApartmentAddress/$1');

$routes->get('login', 'AuthController::login');
$routes->post('auth/sendOTP', 'AuthController::sendOTP');
$routes->post('auth/verifyOTP', 'AuthController::verifyOTP');
$routes->get('logout', 'AuthController::logout');


$routes->get('login', 'AuthController::index');
$routes->post('sendOTP', 'AuthController::sendOTP');
$routes->post('verifyOTP', 'AuthController::verifyOTP');
$routes->get('logout', 'AuthController::logout');

$routes->get('order', 'Order::index', ['filter' => 'auth']);
$routes->get('order/cart', 'Order::cart', ['filter' => 'auth']);
$routes->get('order/checkout', 'Order::checkout', ['filter' => 'auth']);
$routes->post('order/addToCart', 'Order::addToCart', ['filter' => 'auth']);
$routes->post('order/placeOrder', 'Order::placeOrder', ['filter' => 'auth']);
$routes->get('order/getApartments', 'Order::getApartments', ['filter' => 'auth']);
$routes->get('order/getApartmentAddress/(:num)', 'Order::getApartmentAddress/$1', ['filter' => 'auth']);
$routes->get('order', 'Order::index', ['filter' => 'auth']);
$routes->get('order/cart', 'Order::cart', ['filter' => 'auth']);
$routes->post('order/add-to-cart', 'Order::addToCart', ['filter' => 'auth']);

 $routes->get('logout', 'AuthController::logout');
$routes->get('auth/logout', 'AuthController::logout');

$routes->get('order-tracking', 'OrderTracking::index');
$routes->get('order-tracking/getStatus/(:num)', 'OrderTracking::getStatus/$1');

$routes->get('adminOrder', 'AdminOrder::index');               // List all pending orders
$routes->get('adminOrder/confirm/(:num)', 'AdminOrder::confirm/$1'); // Confirm order by ID

$routes->get('admin-report', 'AdminReport::index');               // All orders
$routes->get('admin-report/filter/(:any)', 'AdminReport::filter/$1'); // Filter by status

  

// Protect order routes
$routes->group('', ['filter' => 'authFilter'], function($routes){
    $routes->get('order', 'Order::index');
    $routes->get('cart', 'Order::cart');
    $routes->get('checkout', 'Order::checkout');
      $routes->get('order/cart', 'Order::cart');
    
});



