/**
 * Mass Send Routes - Multi-tenant
 * 
 * Handles mass messaging campaigns, schedules, and reminders with tenant isolation
 * 
 * @module routes/mass-send
 */

const express = require('express');
const MassSendController = require('../controllers/MassSendController');
const { logger } = require('../config/logger');

const router = express.Router();

// Log route registration
logger.info('Registering mass-send routes');

// Note: requireAuth is applied globally in server.js for /api/tenant/* routes

// ===== HISTORY (Send Now) =====
router.get('/history', MassSendController.getHistory);
router.post('/history', MassSendController.createHistory);
router.patch('/history/:id/status', MassSendController.updateStatus);
router.patch('/history/:id/message', MassSendController.updateMessage);
router.patch('/history/:id/archive', MassSendController.archive);
router.delete('/history/:id', MassSendController.delete);

// ===== SCHEDULES =====
router.get('/schedules', MassSendController.getSchedules);
router.post('/schedule', MassSendController.createSchedule);
router.get('/schedule/:id', MassSendController.getSchedule);
router.put('/schedule/:id', MassSendController.updateSchedule);
router.patch('/schedule/:id/cancel', MassSendController.cancelSchedule);
router.delete('/schedule/:id', MassSendController.deleteSchedule);

logger.info('Mass-send schedule routes registered:', {
  getSchedules: !!MassSendController.getSchedules,
  getSchedule: !!MassSendController.getSchedule,
  createSchedule: !!MassSendController.createSchedule,
  updateSchedule: !!MassSendController.updateSchedule,
  cancelSchedule: !!MassSendController.cancelSchedule
});

// ===== REMINDERS =====
router.get('/reminders', MassSendController.getReminders);
router.post('/reminder', MassSendController.createReminder);
router.patch('/reminder/:id/cancel', MassSendController.cancelReminder);
router.delete('/reminder/:id', MassSendController.deleteReminder);

// ===== LOGS =====
router.get('/logs/:type/:id', MassSendController.getLogs);

module.exports = router;
