const express = require("express")
const requireAuth = require("../middleware/requireAuth")
const { setCommentLike } = require("../services/commentLike.service")

const router = express.Router()

// Body: { commentId: number, like: boolean | 0 | 1 }
router.post("/", requireAuth, async (req, res) => {
  try {
    const { commentId, like } = req.body || {}
    const result = await setCommentLike({ commentId, userId: req.auth.userId, like })
    res.json({
      commentId: Number(commentId),
      likeCount: result.likeCount,
      liked: result.liked,
      delta: result.delta,
    })
  } catch (err) {
    res.status(400).json({ error: err.message || "Like iÅŸlemi baÅŸarÄ±sÄ±z" })
  }
})

module.exports = router
