import settingsService from '../services/settingsService.js';
import logAudit from '../utils/audit.js';

export const get = async (req, res, next) => {
  try {
    const settings = await settingsService.getSettings();
    res.json({ success: true, data: settings });
  } catch (error) {
    next(error);
  }
};

export const update = async (req, res, next) => {
  try {
    const settings = await settingsService.updateSettings(req.body);
    logAudit(req, 'SETTINGS_UPDATED', 'settings', String(settings?._id || ''), {
      fields: Object.keys(req.body || {}),
    });
    res.json({ success: true, message: 'Settings updated', data: settings });
  } catch (error) {
    next(error);
  }
};
