import { Router } from 'express';
import * as customerController from '../controllers/customer.controller.js';
import { authenticate, requirePermission, requireCustomerAccess } from '../middleware/auth.js';

const router = Router();

router.put('/:id', authenticate, requirePermission('customers:update'), customerController.updateMeter);
router.delete('/:id', authenticate, requirePermission('customers:delete'), customerController.deleteMeter);

// Meter readings
router.get('/:meterId/readings', authenticate, customerController.getMeterReadings);
router.post('/:meterId/readings', authenticate, requirePermission('customers:update'), customerController.addMeterReading);
router.put('/:meterId/readings/:readingId', authenticate, requirePermission('customers:update'), customerController.updateMeterReading);
router.delete('/:meterId/readings/:readingId', authenticate, requirePermission('customers:delete'), customerController.deleteMeterReading);

// Status-Update (Zählerstand als übertragen markieren)
router.patch('/:meterId/readings/:readingId/transfer', authenticate, requirePermission('customers:update'), customerController.markReadingTransferred);

// Portal: Zählerstand melden (Kunde)
router.post('/:meterId/readings/report', authenticate, customerController.reportMeterReading);

// Portal: Eigene Zähler laden
router.get('/my-meters', authenticate, customerController.getMyMeters);

export default router;
