import { Router } from 'express';
import {
  createQuestion,
  updateQuestion,
  deleteQuestion,
  adminListByCourse,
  submitUserQuestion,
  listPending,
  approveQuestion,
  rejectQuestion,
  importQuestions,
  downloadTemplate,
} from '../controllers/question.controller.js';
import { authenticate, requireAdmin } from '../middleware/auth.middleware.js';
import { uploadSpreadsheet } from '../middleware/upload.middleware.js';

const router = Router();

// User submissions (need approval)
router.post('/submit', authenticate, submitUserQuestion);

// Admin approvals
router.get('/pending', authenticate, requireAdmin, listPending);
router.post('/:id/approve', authenticate, requireAdmin, approveQuestion);
router.post('/:id/reject', authenticate, requireAdmin, rejectQuestion);

// Admin import
router.get('/template', authenticate, requireAdmin, downloadTemplate);
router.post('/import', authenticate, requireAdmin, uploadSpreadsheet, importQuestions);

// Admin CRUD
router.get('/course/:courseId', authenticate, requireAdmin, adminListByCourse);
router.post('/', authenticate, requireAdmin, createQuestion);
router.patch('/:id', authenticate, requireAdmin, updateQuestion);
router.delete('/:id', authenticate, requireAdmin, deleteQuestion);

export default router;
