// routes/storeRoutes.js
const express = require('express');
const router = express.Router();
const storeController = require('../controllers/storeController');
const registerController = require('../controllers/registerController');
const { authenticate, authorize } = require('../middleware/auth'); // Adjust path as needed

// ============================================
// STORE ROUTES
// ============================================

router.get('/', storeController.getAllStores);

router.use(authenticate);

// Get all stores with pagination and search
// GET /api/stores?page=1&limit=20&search=downtown


// Get single store by ID
// GET /api/stores/:id
router.get('/:id', authenticate, storeController.getStoreById);

// Create new store
// POST /api/stores
// Body: { name, code, address, city, state, country, postalCode, phone, email, taxId }
router.post('/', authenticate, authorize(['admin', 'manager','Cashier']), storeController.createStore);

// Update store
// PUT /api/stores/:id
// Body: { name, code, address, city, state, country, postalCode, phone, email, taxId }
router.put('/:id', authenticate, authorize(['admin', 'manager']), storeController.updateStore);

// Deactivate store
// PUT /api/stores/:id/deactivate
router.put('/:id/deactivate', authenticate, authorize(['admin', 'manager']), storeController.deactivateStore);

// Activate store
// PUT /api/stores/:id/activate
router.put('/:id/activate', authenticate, authorize(['admin', 'manager']), storeController.activateStore);

// Delete store (soft delete)
// DELETE /api/stores/:id
router.delete('/:id', authenticate, authorize(['admin']), storeController.deleteStore);

module.exports = router;