import { authenticate } from '../../plugins/auth.js'
import { getSupportHandles } from '../../services/config.service.js'

/**
 * Support channels (WA + Telegram). Sourced from `app_config.support_handles_json`,
 * editable by CC. Authenticated so unauthenticated callers can't enumerate the
 * channels (rate-limit hardening, not a secret).
 *
 * Originally registered under /api/client (Phase 4 Tanya Admin sheet). Promoted
 * to /api/shared when the mitra Profil screen started linking the same WA/TG
 * contacts — same data, both audiences.
 */
export const sharedSupportRoutes = async (app) => {
  app.get('/support-handles', { preHandler: authenticate }, async (_request, reply) => {
    const handles = await getSupportHandles()
    return reply.send({ success: true, data: handles })
  })
}
