const express = require('express');
const db = require('../config/database');
const router = express.Router();

// Get all standards
router.get('/standards', async (req, res) => {
  try {
    const [rows] = await db.execute(
      'SELECT * FROM standards WHERE status = ? ORDER BY display_order',
      ['active']
    );
    res.json(rows);
  } catch (error) {
    res.status(500).json({ message: 'Server error: ' + error.message });
  }
});

// Get all divisions
router.get('/divisions', async (req, res) => {
  try {
    const [rows] = await db.execute(
      'SELECT * FROM divisions WHERE status = ? ORDER BY display_order',
      ['active']
    );
    res.json(rows);
  } catch (error) {
    res.status(500).json({ message: 'Server error: ' + error.message });
  }
});

// Get roll numbers from database
router.get('/roll-numbers', async (req, res) => {
  try {
    const [rows] = await db.execute(
      'SELECT id, number as name FROM roll_numbers WHERE status = ? ORDER BY display_order',
      ['active']
    );
    res.json(rows);
  } catch (error) {
    res.status(500).json({ message: 'Server error: ' + error.message });
  }
});

module.exports = router;