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

// Update client's own details (authenticated clients only)
router.put('/my-details', authenticateToken, clientController.updateMyDetails);

// Get all clients with user data
router.get('/', clientController.getAll);

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

// Get client by ID
router.get('/:id', clientController.getById);

// Create new client by admin (creates user and client in one request)
router.post('/admin', requireAdmin, clientController.createByAdmin);

// Create new client
router.post('/', clientController.create);

// Update client
router.put('/:id', clientController.update);

// Delete client
router.delete('/:id', clientController.delete);

module.exports = router;

