const express = require('express');
const authMiddleware = require('../middlewares/authMiddleware');

/**
 * User Routes
 * Protected endpoints (JWT authentication required)
 * 
 * @param {Container} container - DI Container
 */
function createUserRoutes(container) {
  const router = express.Router();

  // UserController lekérése a DI Container-ből
  const userController = container.resolve('UserController');

  /**
   * GET /api/users/me - Bejelentkezett user adatai
   * Headers: Authorization: Bearer <token>
   */
  router.get('/me', authMiddleware, (req, res) => userController.getMe(req, res));

  /**
   * PUT /api/users/me - User profil frissítése
   * Headers: Authorization: Bearer <token>
   * Body: { name }
   */
  router.put('/me', authMiddleware, (req, res) => userController.updateMe(req, res));

  /**
   * GET /api/users - Összes user lekérése (protected)
   * Headers: Authorization: Bearer <token>
   */
  router.get('/', authMiddleware, (req, res) => userController.getAll(req, res));

  /**
   * GET /api/users/:id - User lekérése ID alapján (protected)
   * Headers: Authorization: Bearer <token>
   */
  router.get('/:id', authMiddleware, (req, res) => userController.getById(req, res));

  /**
   * OPTIONS /api/users/* - CORS preflight
   */
  router.options('*', (req, res) => res.sendStatus(204));

  return router;
}

module.exports = createUserRoutes;
