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

const router = Router();

// List all equipment types
router.get(
  '/',
  authenticate,
  ausruestungTypController.getAll.bind(ausruestungTypController)
);

// Equipment-specific type management (BEFORE /:id to avoid route conflicts)
router.get(
  '/equipment/:ausruestungId',
  authenticate,
  ausruestungTypController.getTypesForEquipment.bind(ausruestungTypController)
);

router.put(
  '/equipment/:ausruestungId',
  authenticate,
  requirePermission('ausruestung:manage_types'),
  ausruestungTypController.setTypesForEquipment.bind(ausruestungTypController)
);

// Get single equipment type
router.get(
  '/:id',
  authenticate,
  ausruestungTypController.getById.bind(ausruestungTypController)
);

// CRUD — permission-protected
router.post(
  '/',
  authenticate,
  requirePermission('ausruestung:manage_types'),
  ausruestungTypController.create.bind(ausruestungTypController)
);

router.patch(
  '/:id',
  authenticate,
  requirePermission('ausruestung:manage_types'),
  ausruestungTypController.update.bind(ausruestungTypController)
);

router.delete(
  '/:id',
  authenticate,
  requirePermission('ausruestung:manage_types'),
  ausruestungTypController.deleteTyp.bind(ausruestungTypController)
);

export default router;
