'use strict';
const router = require('express').Router();
const db = require('../db/db');
const { authMiddleware } = require('../middleware/auth');

router.use(authMiddleware);

/* GET /api/exam9/variants — { variant: test_id } map for assigning variants as homework */
router.get('/variants', (_req, res) => {
  const rows = db.prepare(
    'SELECT evt.variant, evt.test_id FROM exam9_variant_tests evt JOIN tests t ON t.id = evt.test_id ORDER BY evt.variant'
  ).all();
  const map = {};
  for (const r of rows) map[r.variant] = r.test_id;
  res.json({ variants: map });
});

module.exports = router;
