const express = require('express');
const router = express.Router();
const { authenticateToken } = require('../middleware/auth');
const { requireAdmin, canModifyTickets } = require('../middleware/roleCheck');
const AiController = require('../controllers/ai.controller');

// Alle AI-Routen erfordern Login
router.use(authenticateToken);

// Status (alle eingeloggten User)
router.get('/status', AiController.getStatus);

// Chat (alle Staff-Rollen)
router.post('/chat', AiController.chat);

// Wissensdatenbank – lesen: alle Staff
router.get('/knowledge-base', AiController.getKnowledgeBase);

// Wissensdatenbank – schreiben/bearbeiten/löschen: nur Admins
router.post('/knowledge-base/import-text', requireAdmin, AiController.importTextToKb);
router.post('/knowledge-base/import-url', requireAdmin, AiController.importUrlToKb);
router.post('/knowledge-base/import-crawl', requireAdmin, AiController.importCrawlToKb);
router.post('/knowledge-base', requireAdmin, AiController.addKnowledgeEntry);
router.put('/knowledge-base/:id', requireAdmin, AiController.updateKnowledgeEntry);
router.post('/knowledge-base/:id/images', requireAdmin, AiController.uploadKbImage);
router.delete('/knowledge-base/:id/images/:filename', requireAdmin, AiController.deleteKbImage);
router.delete('/knowledge-base/:id', requireAdmin, AiController.deleteKnowledgeEntry);

module.exports = router;
