/**
 * Tier routes for SentryAgent.ai AgentIdP.
 * Mounts tier status and upgrade endpoints under /api/tiers.
 */

import { Router, RequestHandler } from 'express';
import { TierController } from '../controllers/TierController.js';
import { asyncHandler } from '../utils/asyncHandler.js';

/**
 * Creates and returns the Express router for tier management endpoints.
 *
 * Routes:
 *   GET  /tiers/status   — authenticated; returns current tier, limits, and usage
 *   POST /tiers/upgrade  — authenticated; initiates a Stripe checkout for a tier upgrade
 *
 * @param controller - The tier controller instance.
 * @param authMiddleware - The JWT authentication middleware.
 * @returns Configured Express router.
 */
export function createTiersRouter(
  controller: TierController,
  authMiddleware: RequestHandler,
): Router {
  const router = Router();

  // GET /tiers/status — returns tier, limits, and live usage counters
  router.get(
    '/status',
    authMiddleware,
    asyncHandler(controller.getStatus.bind(controller)),
  );

  // POST /tiers/upgrade — initiates Stripe checkout for a tier upgrade
  router.post(
    '/upgrade',
    authMiddleware,
    asyncHandler(controller.initiateUpgrade.bind(controller)),
  );

  return router;
}
