const express = require('express');
const router = express.Router();
const adminAppointmentController = require('../controllers/adminAppointmentController');
const { authenticateAdmin } = require('../middleware/auth');
const { logAdminOperation } = require('../middleware/adminLogger');
const { requireRole } = require('../middleware/rbac');

/**
 * Admin Appointment Management Routes
 * Base path: /api/v1/admin/appointments
 * All routes require admin authentication
 */

/**
 * @route   GET /api/v1/admin/appointments/statistics
 * @desc    Get appointment statistics report
 * @access  Private (Admin)
 */
router.get(
  '/statistics',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  logAdminOperation,
  adminAppointmentController.getAppointmentStatistics
);

/**
 * @route   GET /api/v1/admin/appointments
 * @desc    Get appointment list with pagination and filters
 * @access  Private (Admin)
 */
router.get(
  '/',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  logAdminOperation,
  adminAppointmentController.getAppointmentList
);

/**
 * @route   GET /api/v1/admin/appointments/:id
 * @desc    Get appointment details
 * @access  Private (Admin)
 */
router.get(
  '/:id',
  authenticateAdmin,
  requireRole(['super_admin', 'admin', 'operator']),
  logAdminOperation,
  adminAppointmentController.getAppointmentDetails
);

/**
 * @route   PUT /api/v1/admin/appointments/:id
 * @desc    Update appointment status
 * @access  Private (Admin)
 */
router.put(
  '/:id',
  authenticateAdmin,
  requireRole(['super_admin', 'admin']),
  logAdminOperation,
  adminAppointmentController.updateAppointmentStatus
);

module.exports = router;
