const { BookingRule } = require('../models');

/**
 * 根据服务类型获取预约规则（公开接口）
 */
const getRuleByServiceType = async (req, res) => {
  try {
    const { serviceType } = req.params;
    
    const rule = await BookingRule.findOne({
      where: { 
        serviceType,
        status: 'active'
      },
      attributes: ['serviceType', 'rules']
    });
    
    res.json({
      code: 0,
      message: 'success',
      data: rule ? { rules: rule.rules } : { rules: '' }
    });
  } catch (error) {
    console.error('Get booking rule error:', error);
    res.status(500).json({
      code: 500,
      message: '获取预约规则失败',
      data: null
    });
  }
};

module.exports = {
  getRuleByServiceType
};
