const pool = require('../config/db');
const asyncHandler = require('../middlewares/asyncHandler');
const {
  getFormWithQuestions,
  getFormById,
} = require('../repositories/dynamicFormRepository');

// Get form with sat_questions
exports.getFormWithQuestions = asyncHandler(async (req, res) => {
    const rows = await getFormWithQuestions();
    res.status(200).json({ success: true, data: rows });
});

// Get form by ID
exports.getFormById = asyncHandler(async (req, res) => {
    const { id } = req.params;
    const form = await getFormById(id);
    if (!form) {
        return res.status(404).json({ success: false, message: 'Form not found' });
    }
    
    res.status(200).json({ success: true, data: form });
});