/**
 * Vacation Settings Controller
 *
 * 연차 계산 규칙 설정 GET/PUT
 */

const vacationSettingsModel = require('../models/vacationSettingsModel');

async function getSettings(req, res, next) {
  try {
    const data = await vacationSettingsModel.getAll();
    res.json({ success: true, data });
  } catch (err) { next(err); }
}

async function updateSettings(req, res, next) {
  try {
    const { settings } = req.body;
    if (!settings || !Array.isArray(settings)) {
      return res.status(400).json({ success: false, error: 'settings 배열이 필요합니다' });
    }
    const data = await vacationSettingsModel.updateSettings(settings, req.user.user_id);
    res.json({ success: true, data, message: '설정이 업데이트되었습니다' });
  } catch (err) { next(err); }
}

module.exports = { getSettings, updateSettings };
