import cors from 'cors';
import dotenv from 'dotenv';
import express from 'express';
import { requireTraceContext } from './core/guards/trace-context.guard';
import { mtlsGuard } from './core/guards/mtls.guard';
import { slaGuard } from './core/guards/sla.guard';

// API Routes
import aiRoutes from './api/routes/ai';
import arbitrageRoutes from './api/routes/arbitrage';
import auditRoutes from './api/routes/audit';
import authRoutes from './api/routes/auth';
import billingRoutes from './api/routes/billing';
import bizRoutes from './api/routes/biz';
import certificateRoutes from './api/routes/certificate';
import chatbotRoutes from './api/routes/chatbot';
import commandRoutes from './api/routes/command';
import configRoutes from './api/routes/config';
import liteConsoleRoutes from './api/routes/console_lite';
import creativeRoutes from './api/routes/creative';
import customerRoutes from './api/routes/customer';
import dynamicPricingRoutes from './api/routes/dynamicPricing';
import financeRoutes from './api/routes/finance';
import governanceRoutes from './api/routes/governance';
import leaderboardRoutes from './api/routes/leaderboard';
import marketingRoutes from './api/routes/marketing';
import nodeRoutes from './api/routes/node';
import orderRoutes from './api/routes/order';
import productRoutes from './api/routes/product';
import publishRoutes from './api/routes/publish';
import reportRoutes from './api/routes/report';
import sovereigntyRoutes from './api/routes/sovereignty';
import strategyRoutes from './api/routes/strategy';
import autopilotRoutes from './api/routes/autopilot';
import syncRoutes from './api/routes/sync';
import telemetryRoutes from './api/routes/telemetry';
import tenantRoutes from './api/routes/tenant';
import traceRoutes from './api/routes/trace';
import tradeRoutes from './api/routes/trade';
import vaultRoutes from './api/routes/vault';
import webhookRoutes from './api/routes/webhook';
import currencyRoutes from './api/routes/currency';

dotenv.config();

const app = express();

// Global Middleware
app.use(cors());
app.use(express.json());
// app.use(requireTraceContext); 
// app.use(mtlsGuard); 
// app.use(slaGuard); 

// API Routes (V1)
app.use('/api/v1/auth', authRoutes);
app.use('/api/v1/billing', billingRoutes);
app.use('/api/v1/certificate', certificateRoutes);
app.use('/api/v1/arbitrage', arbitrageRoutes);
app.use('/api/v1/orders', orderRoutes);
app.use('/api/v1/biz', bizRoutes);
app.use('/api/v1/creative', creativeRoutes);
app.use('/api/v1/customer', customerRoutes);
app.use('/api/v1/report', reportRoutes);
app.use('/api/v1/lite', liteConsoleRoutes);
app.use('/api/v1/tenant', tenantRoutes);
app.use('/api/v1/product', productRoutes);
app.use('/api/v1/publish', publishRoutes);
app.use('/api/v1/trade', tradeRoutes);
app.use('/api/v1/finance', financeRoutes);
app.use('/api/v1/strategy', strategyRoutes);
app.use('/api/v1/autopilot', autopilotRoutes);
app.use('/api/v1/sovereignty', sovereigntyRoutes);
app.use('/api/v1/governance', governanceRoutes);
app.use('/api/v1/audit', auditRoutes);
app.use('/api/v1/trace', traceRoutes);
app.use('/api/v1/sync', syncRoutes);
app.use('/api/v1/config', configRoutes);
app.use('/api/v1/vault', vaultRoutes);
app.use('/api/v1/telemetry', telemetryRoutes);
app.use('/api/v1/webhook', webhookRoutes);
app.use('/api/v1/node', nodeRoutes);
app.use('/api/v1/ai', aiRoutes);
app.use('/api/v1/chatbot', chatbotRoutes);
app.use('/api/v1/command', commandRoutes);
app.use('/api/v1/marketing', marketingRoutes);
app.use('/api/v1/leaderboard', leaderboardRoutes);
app.use('/api/v1/dynamic-pricing', dynamicPricingRoutes);
app.use('/api/v1/currency', currencyRoutes);

export { app };
