import { Router } from 'express';
import buchungskategorieController from '../controllers/buchungskategorie.controller';
import { authenticate } from '../middleware/auth.middleware';
import { requirePermission } from '../middleware/rbac.middleware';

const router = Router();

// GET /           — all categories (admin view, includes inactive)
router.get(
  '/',
  authenticate,
  requirePermission('fahrzeugbuchungen:view'),
  buchungskategorieController.list.bind(buchungskategorieController)
);

// GET /active     — only active categories (for booking forms)
router.get(
  '/active',
  authenticate,
  requirePermission('fahrzeugbuchungen:view'),
  buchungskategorieController.listActive.bind(buchungskategorieController)
);

// POST /          — create new category
router.post(
  '/',
  authenticate,
  requirePermission('fahrzeugbuchungen:manage'),
  buchungskategorieController.create.bind(buchungskategorieController)
);

// PATCH /:id      — update category
router.patch(
  '/:id',
  authenticate,
  requirePermission('fahrzeugbuchungen:manage'),
  buchungskategorieController.update.bind(buchungskategorieController)
);

// DELETE /:id     — soft-delete (deactivate)
router.delete(
  '/:id',
  authenticate,
  requirePermission('fahrzeugbuchungen:manage'),
  buchungskategorieController.deactivate.bind(buchungskategorieController)
);

// DELETE /:id/permanent — hard delete
router.delete(
  '/:id/permanent',
  authenticate,
  requirePermission('fahrzeugbuchungen:manage'),
  buchungskategorieController.remove.bind(buchungskategorieController)
);

export default router;
