import { Router } from "express"
import { addAsync } from "@awaitjs/express"
import { healthcheck } from "../endpoints/healthcheck.js"
import { testSentry } from "../endpoints/sentry-test.js"
import { handleSlackEvents } from "../endpoints/slack-events.js"
import { ROUTES } from "../constants/index.js"

// Root-level public routes (no prefix)
export const rootRoutes = Router()

rootRoutes.get(ROUTES.ROOT, (req, res) => {
  return res.status(200).send("OK")
})

// Public API routes (mounted under API_BASE_ROUTE)
// Using addAsync to properly handle async route handlers and pass errors to Express error middleware
const publicApiRouter = addAsync(Router()) as any
export const publicApiRoutes = publicApiRouter

publicApiRouter.get(ROUTES.TEST_SENTRY, testSentry)
publicApiRouter.postAsync(ROUTES.SLACK_EVENTS, handleSlackEvents)
publicApiRouter.get(ROUTES.HEALTHCHECK, healthcheck)
