const express = require('express');
const router = express.Router();
const patientReportController = require('../controllers/patientReportController');
const authMiddleware = require('../middleware/authMiddleware');

// Get patient report by request ID
router.get('/request/:requestId', authMiddleware, patientReportController.getPatientReportByRequestId);

// Create or update patient report for a request
router.post('/request/:requestId', authMiddleware, patientReportController.createOrUpdatePatientReport);
router.put('/request/:requestId', authMiddleware, patientReportController.createOrUpdatePatientReport);

// Get all drugs for selection
router.get('/drugs', authMiddleware, patientReportController.getAllDrugs);

// Create new drug
router.post('/drugs', authMiddleware, patientReportController.createDrug);

// Update existing items
router.put('/fluids/:id', authMiddleware, patientReportController.updateFluid);
router.put('/drugs-administered/:id', authMiddleware, patientReportController.updateDrug);
router.put('/observations/:id', authMiddleware, patientReportController.updateObservation);

// Get observation types
router.get('/observation-types', authMiddleware, patientReportController.getObservationTypes);

// Delete specific items
router.delete('/fluids/:id', authMiddleware, patientReportController.deleteFluid);
router.delete('/drugs-administered/:id', authMiddleware, patientReportController.deleteDrug);
router.delete('/observations/:id', authMiddleware, patientReportController.deleteObservation);

// Public route for patient report request verification (no auth required)
router.post('/public/request', patientReportController.getPatientReportByEmailAndCode);

module.exports = router;
