const express = require('express');
const router = express.Router();
const { authenticate } = require('../middlewares/auth');
const permission = require('../middlewares/permission');
const machineHistoryCardController = require('../controllers/machineHistoryCardController');
const machineHistoryCardPDFController = require('../controllers/machineHistoryCardPDFController');

// All routes require authentication
router.use(authenticate);

// Get all machine history cards
router.get('/', machineHistoryCardController.getAll);

// Get machine history by machine ID
router.get('/machine/:machineId', machineHistoryCardController.getByMachineId);

// Get by ID
router.get('/:id', machineHistoryCardController.getById);

// Print PDF (single row)
router.get('/:id/pdf', permission.requireOperation('MAINTENANCE', 'MACHINE_HISTORY', 'PRINT'), machineHistoryCardPDFController.generatePDF);

// Create
router.post('/', machineHistoryCardController.create);

// Update
router.put('/:id', machineHistoryCardController.update);

// Delete
router.delete('/:id', machineHistoryCardController.delete);

module.exports = router;
