const http = require('http');
const app = require('./app');
const env = require('./config/env');
const { initSocket } = require('./config/socket');
const { warmupInfrastructure } = require('./config/services');
const { ensureUserTable } = require('./services/userService');
const logger = require('./utils/logger');

const server = http.createServer(app);
initSocket(server);

server.listen(env.port, async () => {
  logger.success(`Bookibra API ${env.port} portunda ayakta (NODE_ENV=${env.nodeEnv})`);
  const readiness = await warmupInfrastructure();
  logger.info(`Servis hazirlik durumu: ${JSON.stringify(readiness)}`);
  await ensureUserTable();
});
