import http from "node:http";

import app from "./app.js";
import { env } from "./config/env.js";
import { attachSocketServer } from "./config/socket.js";
import { initializeTrackingCleanupJob } from "./jobs/cleanOldLocations.js";
import { initializeMgxAlertEngine } from "./services/mgxAlertEngine.js";
import { initializeTrackingService } from "./services/trackingService.js";

const httpServer = http.createServer(app);
const io = attachSocketServer(httpServer);

app.set("io", io);
initializeMgxAlertEngine(io);
initializeTrackingService(io);
initializeTrackingCleanupJob();

httpServer.listen(env.port, () => {
  console.log(`SCF Accounting API listening on port ${env.port}`);
});
