import { Router } from 'express'
import { generateSuggestions } from '../llm.js'

const router = Router()

router.post('/', async (req, res) => {
  const { context, question } = req.body as { context?: string[]; question?: string }
  if (!question) {
    return res.status(400).json({ message: 'question이 필요합니다.' })
  }

  try {
    const suggestions = await generateSuggestions({
      context: Array.isArray(context) ? context : [],
      question,
    })
    return res.json({ suggestions })
  } catch (err) {
    return res.status(500).json({ message: '답변 후보를 생성하지 못했습니다.' })
  }
})

export default router
