import app from './app.js';
import { startAllCronJobs } from './cron/index.js';
import { logger } from './utils/logger.js';
import { testConnection } from './config/database.js';

const port = process.env.PORT || 5000;

const start = async () => {
  try {
    // Test database connection
    await testConnection();
    logger.success('Database connected');

    // Start server
    app.listen(port, () => {
      logger.info(`Server running on http://localhost:${port}`);
      startAllCronJobs();
    });
  } catch (error) {
    logger.error('Failed to start server', error);
    process.exit(1);
  }
};

start();
