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

const router = Router();

// ==================== INVOICE CRUD ====================

// Alle Rechnungen für ein EnergyContractDetails abrufen
// GET /api/energy-details/:ecdId/invoices
router.get(
  '/:ecdId/invoices',
  authenticate,
  requirePermission('contracts:read'),
  invoiceController.getInvoices
);

// Einzelne Rechnung abrufen
// GET /api/energy-details/:ecdId/invoices/:invoiceId
router.get(
  '/:ecdId/invoices/:invoiceId',
  authenticate,
  requirePermission('contracts:read'),
  invoiceController.getInvoice
);

// Neue Rechnung hinzufügen
// POST /api/energy-details/:ecdId/invoices
router.post(
  '/:ecdId/invoices',
  authenticate,
  requirePermission('contracts:update'),
  invoiceController.addInvoice
);

// Rechnung aktualisieren
// PUT /api/energy-details/:ecdId/invoices/:invoiceId
router.put(
  '/:ecdId/invoices/:invoiceId',
  authenticate,
  requirePermission('contracts:update'),
  invoiceController.updateInvoice
);

// Rechnung löschen
// DELETE /api/energy-details/:ecdId/invoices/:invoiceId
router.delete(
  '/:ecdId/invoices/:invoiceId',
  authenticate,
  requirePermission('contracts:delete'),
  invoiceController.deleteInvoice
);

export default router;
