/**
 * Ranking Routes
 *
 * Route definitions for ranking and achievement endpoints.
 * All routes are configured with appropriate middleware.
 */

import { Router } from 'express';
import rankingController from './ranking.controller';
import { authenticate, requireAdmin } from '../../shared/middleware/auth.middleware';

// ============================================
// ROUTER
// ============================================

export const rankingRoutes = Router();

// ============================================
// PUBLIC ROUTES (No authentication required)
// ============================================

/**
 * @route   GET /api/ranking/global
 * @desc    Get global ranking (anonymous - no personal data)
 * @access  Public
 */
rankingRoutes.get('/global', rankingController.getGlobalRanking);

/**
 * @route   GET /api/ranking/period
 * @desc    Get period-based ranking (daily, weekly, monthly, all-time)
 * @query   period - daily|weekly|monthly|all-time (default: all-time)
 * @access  Public
 */
rankingRoutes.get('/period', rankingController.getPeriodRanking);

/**
 * @route   GET /api/ranking/module/:moduleId
 * @desc    Get module ranking (anonymous)
 * @access  Public
 */
rankingRoutes.get('/module/:moduleId', rankingController.getModuleRanking);

/**
 * @route   GET /api/ranking/statistics
 * @desc    Get global ranking statistics
 * @access  Public
 */
rankingRoutes.get('/statistics', rankingController.getRankingStatistics);

/**
 * @route   GET /api/ranking/modules
 * @desc    Get list of modules with ranking availability
 * @access  Public
 */
rankingRoutes.get('/modules', rankingController.getModulesWithRanking);

/**
 * @route   GET /api/achievements
 * @desc    Get all available badges/achievements
 * @access  Public
 */
rankingRoutes.get('/achievements', rankingController.getAllAchievements);

// ============================================
// AUTHENTICATED ROUTES
// ============================================

/**
 * @route   GET /api/ranking/my-position
 * @desc    Get authenticated user's ranking position (anonymous data only)
 * @access  Private
 */
rankingRoutes.get('/my-position', authenticate, rankingController.getMyPosition);

/**
 * @route   GET /api/ranking/streak
 * @desc    Get authenticated user's current streak information
 * @access  Private
 */
rankingRoutes.get('/streak', authenticate, rankingController.getUserStreak);

/**
 * @route   GET /api/ranking/around-me
 * @desc    Get ranking around authenticated user's position
 * @access  Private
 */
rankingRoutes.get('/around-me', authenticate, rankingController.getRankingAroundMe);

/**
 * @route   GET /api/achievements/my
 * @desc    Get authenticated user's badges with progress
 * @access  Private
 */
rankingRoutes.get('/achievements/my', authenticate, rankingController.getMyAchievements);

/**
 * @route   GET /api/achievements/my/unlocked
 * @desc    Get only unlocked badges for authenticated user
 * @access  Private
 */
rankingRoutes.get('/achievements/my/unlocked', authenticate, rankingController.getUnlockedAchievements);

/**
 * @route   GET /api/achievements/summary
 * @desc    Get user's achievement summary
 * @access  Private
 */
rankingRoutes.get('/achievements/summary', authenticate, rankingController.getAchievementSummary);

/**
 * @route   GET /api/achievements/:badgeCode
 * @desc    Get progress for a specific badge
 * @access  Private
 */
rankingRoutes.get('/achievements/:badgeCode', authenticate, rankingController.getBadgeProgress);

/**
 * @route   POST /api/ranking/update-me
 * @desc    Force update authenticated user's ranking
 * @access  Private
 */
rankingRoutes.post('/update-me', authenticate, rankingController.updateMyRanking);

// ============================================
// ADMIN ROUTES (Would require admin middleware)
// ============================================

/**
 * @route   POST /api/ranking/recalculate
 * @desc    Recalculate all rankings
 * @access  Admin
 */
rankingRoutes.post('/recalculate', authenticate, requireAdmin, rankingController.recalculateRankings);

/**
 * @route   POST /api/achievements/initialize
 * @desc    Initialize all badges in the database
 * @access  Admin
 */
rankingRoutes.post('/achievements/initialize', authenticate, requireAdmin, rankingController.initializeBadges);

// ============================================
// EXPORTS
// ============================================

export default rankingRoutes;