/**
 * Dispatch Module Routes
 * ERP Transportistas
 *
 * Routes for dispatch center, certifications, shifts, and rules.
 * Module: MAI-005 Despacho
 * Sprint: S2 - TASK-007
 */

import { Router } from 'express';
import { AppDataSource } from '../../config/typeorm.js';
import {
  createDispatchController,
  createCertificacionController,
  createTurnoController,
  createRuleController,
  createGpsIntegrationController,
} from './controllers/index.js';

const router = Router();

// Create controller routers with DataSource
const dispatchRouter = createDispatchController(AppDataSource);
const certificacionRouter = createCertificacionController(AppDataSource);
const turnoRouter = createTurnoController(AppDataSource);
const ruleRouter = createRuleController(AppDataSource);
const gpsIntegrationRouter = createGpsIntegrationController(AppDataSource);

// Mount routes
// /api/despacho - Core dispatch operations (boards, units, assignments)
router.use('/', dispatchRouter);

// /api/despacho/certificaciones - Operator certifications
router.use('/certificaciones', certificacionRouter);

// /api/despacho/turnos - Operator shifts
router.use('/turnos', turnoRouter);

// /api/despacho/reglas - Dispatch and escalation rules
router.use('/reglas', ruleRouter);

// /api/despacho/gps - GPS-Dispatch integration (Sprint S3)
router.use('/gps', gpsIntegrationRouter);

export default router;
