const express = require("express")
const router = express.Router()
const badgeService = require("../services/badge.service")
const { ensureBadgesCached } = require("../services/redis/badgeCache.service")
const { endpoints } = require("@shared/contracts")

const { badges } = endpoints

router.get("/", async (req, res) => {
  try {
    const payload = await ensureBadgesCached()
    res.json(badges.badgesListResponseSchema.parse(payload))
  } catch (err) {
    const status = err.statusCode || 500
    res.status(status).json({ error: err.message || "Sunucu hatasi" })
  }
})

module.exports = router
