const router = require("express").Router();
const authRoutes = require("./auth.routes.js");
const superAdminRoutes = require("./dashboard/super/dashboard.routes.js");
const superAdminSupportRoutes = require("./dashboard/super/support.routes.js");
const superAdminSettlementRoutes = require("./dashboard/super/settlement.routes.js");
const emailTemplateRoutes = require("./emailTemplate.routes.js");
const smsTemplateRoutes = require("./smsTemplate.routes.js");
const whatsappTemplateRoutes = require("./whatsappTemplate.routes.js");
const notificationSettingsRoutes = require("./notificationSettings.routes.js");
const zoneAdminRoutes = require("./dashboard/zone/dashboard.routes.js");
const zoneRoutes = require("./zone.routes.js");
const vendorRoutes = require("./vendor.routes.js");
const driverRoutes = require("./driver.routes.js");
const userRoutes = require("./user.routes.js");
const bookingRoutes = require("./booking.routes.js")
const vehicleRoutes = require("./vehicle.routes.js")
const ticketRoutes = require("./ticket.routes.js");
const seoRoutes = require("./seo.routes.js");
const settingRoutes = require("./setting.routes.js");
const paymentRoutes = require("./payment.routes.js");
const invoiceRoutes = require("./invoice.routes.js");
const cmsRoutes = require("./cms.routes.js");
const faqRoutes = require("./faq.routes.js");
// translationRoutes removed

const {
    authLimiter,
    superAdminLimiter,
    zoneAdminLimiter,
    vendorLimiter,
    driverLimiter,
    userLimiter,
    zoneLimiter,
    vehicleLimiter,
} = require("../middlewares/rateLimiter.js");
const { isAuthenticated, allowRoles, restrictStaffScope } = require("../middlewares/authenticate.js");


const { checkPermission } = require("../middlewares/checkPermission.js");
const staffRoutes = require("./dashboard/super/staff.routes.js");
const zoneStaffRoutes = require("./dashboard/zone/staff.routes.js");

const webhookRoutes = require("./dashboard/super/webhook.routes.js");

router.use("/auth", authRoutes);
router.use("/super/staff", isAuthenticated, allowRoles("super-admin"), superAdminLimiter, staffRoutes); // Only Super Admin can manage staff
// Modified to allow staff access to dashboard with permission
router.use("/super", isAuthenticated, allowRoles("super-admin", "staff"), restrictStaffScope("User"), checkPermission("view_dashboard"),  superAdminRoutes);
router.use("/super/support", isAuthenticated, allowRoles("super-admin", "staff"), restrictStaffScope("User"), checkPermission("manage_support"), superAdminLimiter, superAdminSupportRoutes);
router.use("/super/settlement", isAuthenticated, allowRoles("super-admin", "staff"), restrictStaffScope("User"), checkPermission("manage_financials"), superAdminLimiter, superAdminSettlementRoutes);
router.use("/super/webhooks", isAuthenticated, allowRoles("super-admin", "staff"), restrictStaffScope("User"), checkPermission(["manage_settings", "manage_webhooks"]), superAdminLimiter, webhookRoutes);
router.use("/super/email-templates", isAuthenticated, allowRoles("super-admin", "staff"), restrictStaffScope("User"), checkPermission("manage_settings"), superAdminLimiter, emailTemplateRoutes);
router.use("/super/sms-templates", isAuthenticated, allowRoles("super-admin", "staff"), restrictStaffScope("User"), checkPermission("manage_settings"), superAdminLimiter, smsTemplateRoutes);
router.use("/super/whatsapp-templates", isAuthenticated, allowRoles("super-admin", "staff"), restrictStaffScope("User"), checkPermission("manage_settings"), superAdminLimiter, whatsappTemplateRoutes);
router.use("/super/notification-settings", isAuthenticated, allowRoles("super-admin", "staff"), restrictStaffScope("User"), checkPermission("manage_settings"), superAdminLimiter, notificationSettingsRoutes);
router.use("/zone", isAuthenticated, zoneLimiter, zoneRoutes);
router.use("/vendor", vendorLimiter, vendorRoutes);
router.use("/driver", driverLimiter, driverRoutes);
router.use("/user",  userRoutes);
router.use("/tickets", isAuthenticated, ticketRoutes); // Consolidated Ticket & Support
router.use("/booking", bookingRoutes);
router.use("/vehicle", vehicleLimiter, vehicleRoutes);
// Zone Admin Staff Management
router.use("/zone-admin/staff", isAuthenticated, allowRoles("zone-admin", "staff"), restrictStaffScope("ZoneAdmin"), checkPermission("manage_staff"), zoneAdminLimiter, zoneStaffRoutes);
router.use("/zone-admin", isAuthenticated, allowRoles("zone-admin", "staff"), restrictStaffScope("ZoneAdmin"), zoneAdminLimiter, zoneAdminRoutes);

// Vendor Staff Management
router.use("/vendor/staff", require("./vendor.staff.routes.js"));
router.use("/seo", seoRoutes);  // Public SEO landing pages (no auth required for public endpoints)
router.use("/settings", settingRoutes);
router.use("/payment", paymentRoutes);  // Razorpay payment integration
router.use("/invoices", invoiceRoutes); // Invoice management
router.use("/cms", cmsRoutes); // Header, Footer, Banners
router.use("/faq", faqRoutes); // FAQ Management (Advanced system with categories, search, analytics)
// router.use("/translations", translationRoutes);
router.use("/app-languages", require("./app-language.routes")); // Dynamic UI translations
router.use("/env-settings", require("./env.routes")); // Environment Variables Management


module.exports = router;
