import { Router } from 'express';
import { downloadBackup, restore, inspect } from '../controllers/backupController.js';
import { protect } from '../middlewares/auth.js';
import { authorize } from '../middlewares/authorize.js';
import { rateLimit } from '../middlewares/rateLimiter.js';
import { ACTIONS } from '../utils/permissions.js';

const router = Router();

router.get('/', protect, authorize(ACTIONS.BACKUP_MANAGE), downloadBackup);
router.post('/inspect', protect, authorize(ACTIONS.BACKUP_MANAGE), inspect);
router.post(
  '/restore',
  rateLimit({ windowMs: 60 * 60 * 1000, max: 10, message: 'Too many restore attempts. Please try again later.' }),
  protect,
  authorize(ACTIONS.BACKUP_MANAGE),
  restore
);

export default router;
