import { Router } from 'express';
import { sageService } from '../services/SageService.js';

const router = Router();

router.post('/message', (req, res) => {
  const message = req.body?.message;
  if (typeof message !== 'string') {
    res.status(400).json({ error: 'Message must be a string' });
    return;
  }

  const trimmed = message.trim();
  if (!trimmed) {
    res.status(400).json({ error: 'Message cannot be empty' });
    return;
  }

  if (trimmed.length > 500) {
    res.status(400).json({ error: 'Message too long' });
    return;
  }

  res.json(sageService.reply(trimmed));
});

export default router;
