const express = require('express');
const { body } = require('express-validator');
const userController = require('../controllers/userController');
const { authenticateUser } = require('../middleware/auth');

const router = express.Router();

/**
 * User Routes
 * All routes require authentication
 */

/**
 * @route   GET /api/v1/users/profile
 * @desc    Get user profile
 * @access  Private
 */
router.get('/profile', authenticateUser, userController.getProfile);

/**
 * @route   PUT /api/v1/users/profile
 * @desc    Update user profile
 * @access  Private
 */
router.put(
  '/profile',
  authenticateUser,
  [
    body('nickname').optional().isString().trim().isLength({ max: 100 }),
    body('avatar').optional().isString().trim().isLength({ max: 500 }),
    body('realName').optional().isString().trim().isLength({ max: 100 }),
    body('phone').optional().isString().trim().isLength({ max: 20 }),
    body('whatsapp').optional().isString().trim().isLength({ max: 20 }),
    body('wechatId').optional().isString().trim().isLength({ max: 100 }),
  ],
  userController.updateProfile
);

/**
 * @route   PUT /api/v1/users/language
 * @desc    Set language preference
 * @access  Private
 */
router.put(
  '/language',
  authenticateUser,
  [
    body('language').notEmpty().isIn(['zh', 'en', 'es']).withMessage('Language must be one of: zh, en, es'),
  ],
  userController.setLanguage
);

module.exports = router;
