import { Router } from 'express';
import { NLPController } from '../controllers/nlp.controller';
import { authMiddleware } from '../middleware/auth.middleware';
import { rateLimitMiddleware } from '../middleware/rate-limit.middleware';

/**
 * NLP API routes
 */
export function createNLPRoutes(): Router {
  const router = Router();
  const controller = new NLPController();

  // Apply authentication to all NLP routes
  router.use(authMiddleware);

  // Apply rate limiting to prevent abuse
  const nlpRateLimit = rateLimitMiddleware({
    windowMs: 60 * 1000, // 1 minute
    max: 30, // 30 requests per minute
    message: 'Too many NLP requests, please try again later',
  });

  const heavyRateLimit = rateLimitMiddleware({
    windowMs: 60 * 1000, // 1 minute
    max: 10, // 10 requests per minute for heavy operations
    message: 'Too many heavy NLP requests, please try again later',
  });

  // Parse and process text
  router.post('/parse', nlpRateLimit, (req, res) => controller.parse(req, res));

  // Extract entities
  router.post('/extract-entities', nlpRateLimit, (req, res) => controller.extractEntities(req, res));

  // Classify text
  router.post('/classify', nlpRateLimit, (req, res) => controller.classify(req, res));

  // Translation endpoints (heavier operations)
  router.post('/translate', heavyRateLimit, (req, res) => controller.translate(req, res));

  // Language detection
  router.post('/detect-language', nlpRateLimit, (req, res) => controller.detectLanguage(req, res));

  // Get supported languages
  router.get('/languages', (req, res) => controller.getSupportedLanguages(req, res));

  // Cache management
  router.get('/cache/stats', (req, res) => controller.getCacheStats(req, res));
  router.delete('/cache', (req, res) => controller.clearCache(req, res));

  return router;
}

export default createNLPRoutes;