const express = require('express');
const router = express.Router();
const { authenticateAdmin } = require('../middleware/auth');
const { requirePermission } = require('../middleware/rbac');
const adminTranslationController = require('../controllers/adminTranslationController');

/**
 * Admin Translation Routes
 * All routes require admin authentication
 */

// Get all translation categories
router.get(
  '/categories',
  authenticateAdmin,
  requirePermission('translations', 'read'),
  adminTranslationController.getCategories
);

// Get all translations with filtering
router.get(
  '/',
  authenticateAdmin,
  requirePermission('translations', 'read'),
  adminTranslationController.getTranslations
);

// Get translations by key (all languages)
router.get(
  '/:key',
  authenticateAdmin,
  requirePermission('translations', 'read'),
  adminTranslationController.getTranslationsByKey
);

// Create a new translation
router.post(
  '/',
  authenticateAdmin,
  requirePermission('translations', 'create'),
  adminTranslationController.createTranslation
);

// Batch create/update translations
router.post(
  '/batch',
  authenticateAdmin,
  requirePermission('translations', 'create'),
  adminTranslationController.upsertTranslations
);

// Update a translation
router.put(
  '/:id',
  authenticateAdmin,
  requirePermission('translations', 'update'),
  adminTranslationController.updateTranslation
);

// Delete a translation
router.delete(
  '/:id',
  authenticateAdmin,
  requirePermission('translations', 'delete'),
  adminTranslationController.deleteTranslation
);

module.exports = router;
