import { authenticate } from '../../plugins/auth.js'
import { getAnonymityConfig, getSensitivityConfig, getOtpRateLimits } from '../../services/config.service.js'

export const sharedConfigRoutes = async (app) => {
  app.get('/anonymity', async (request, reply) => {
    const config = await getAnonymityConfig()
    return reply.send({ success: true, data: config })
  })

  app.get('/sensitivity', { preHandler: [authenticate] }, async (request, reply) => {
    const config = await getSensitivityConfig()
    return reply.send({ success: true, data: config })
  })

  app.get('/otp', async (request, reply) => {
    const limits = await getOtpRateLimits()
    return reply.send({
      success: true,
      data: { resend_cooldown_seconds: limits.resend_cooldown_seconds },
    })
  })
}
