const express = require('express');
const { query, param } = require('express-validator');
const serviceController = require('../controllers/serviceController');

const router = express.Router();

/**
 * Service Routes
 * Public routes for browsing services and categories
 */

/**
 * @route   GET /api/v1/categories
 * @desc    Get all service categories
 * @access  Public
 */
router.get('/categories', serviceController.getCategories);

/**
 * @route   GET /api/v1/services
 * @desc    Get services with pagination and filtering
 * @access  Public
 */
router.get(
  '/services',
  [
    query('page').optional().isInt({ min: 1 }).withMessage('Page must be a positive integer'),
    query('limit').optional().isInt({ min: 1, max: 100 }).withMessage('Limit must be between 1 and 100'),
    query('categoryKey').optional().isString().withMessage('Category key must be a string'),
    query('language').optional().isIn(['zh', 'en', 'pt']).withMessage('Language must be one of: zh, en, pt'),
  ],
  serviceController.getServices
);

/**
 * @route   GET /api/v1/services/:key
 * @desc    Get service details by key
 * @access  Public
 */
router.get(
  '/services/:key',
  [
    param('key').isString().notEmpty().withMessage('Service key is required'),
    query('language').optional().isIn(['zh', 'en', 'pt']).withMessage('Language must be one of: zh, en, pt'),
  ],
  serviceController.getServiceByKey
);

module.exports = router;
