const express = require('express');
const router = express.Router();
const userController = require('../controllers/userController');
const verifyAccessTokenMiddleware = require('../middleware/verifyAccessToken');
const verifyRole = require('../middleware/verifyRole');

/**
 * All user routes require authentication
 */

// Get user statistics
router.get('/stats', verifyAccessTokenMiddleware, userController.getStats);

// Get all active users with pagination and search
router.get('/', verifyAccessTokenMiddleware, userController.getAll);

// Export users
router.get('/export', verifyAccessTokenMiddleware, userController.exportUsers);

// Get user by id
router.get('/:id', verifyAccessTokenMiddleware, userController.getById);

// Create new user
router.post('/', verifyAccessTokenMiddleware, userController.create);

// Update user
router.put('/:id', verifyAccessTokenMiddleware, userController.update);

// Add subscription
router.post('/:id/subscription', verifyAccessTokenMiddleware, userController.addSubscription);

// Restore user
router.put('/:id/restore', verifyAccessTokenMiddleware, verifyRole(['superadmin']), userController.restore);

// Delete user (soft delete - only superadmin)
router.delete('/:id', verifyAccessTokenMiddleware, verifyRole(['superadmin']), userController.delete);

module.exports = router;
