const express = require('express');
const router = express.Router();
const userController = require('../controllers/userController');
const ambulanceRequestController = require('../controllers/ambulanceRequestController');
const notificationController = require('../controllers/notificationController');
const requireAdmin = require('../middleware/adminMiddleware');
const authenticateToken = require('../middleware/authMiddleware');

// User CRUD routes (must come before /:id routes to avoid conflicts)
// Get all users
router.get('/', userController.getAll);

// Get all clients with user data
router.get('/clients', userController.getAllClients);

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

// Change password for the authenticated user
router.patch('/me/password', authenticateToken, userController.changeMyPassword);

// Get user with all ambulance requests (specific route before generic :id)
router.get('/:id/with-requests', userController.getByIdWithRequests);

// Get ambulance requests by user ID (specific route before generic :id)
router.get('/:id/ambulance-requests', ambulanceRequestController.getByUserId);

// Get notifications for a user (specific route before generic :id)
router.get('/:id/notifications', notificationController.getByUserId);

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

// Update user (admin only)
router.put('/:id', requireAdmin, userController.update);

// Delete user
router.delete('/:id', userController.delete);

module.exports = router;

