// DBIS Core Banking System - Main Entry Point

import './bootstrap/env';
import app from './integration/api-gateway/app';
import { logger } from './infrastructure/monitoring/logger';
import { validateEnvironment } from './shared/config/env-validator';

// Validate environment variables before starting
try {
  validateEnvironment();
} catch (error) {
  logger.error('Environment validation failed', {
    error: error instanceof Error ? error.message : 'Unknown error',
  });
  process.exit(1);
}

const PORT = process.env.PORT || 3000;

// Start server
app.listen(PORT, () => {
  logger.info(`DBIS Core Banking System started on port ${PORT}`);
  logger.info(`Environment: ${process.env.NODE_ENV || 'development'}`);
  logger.info(`API Documentation: http://localhost:${PORT}/api-docs`);
});

// Graceful shutdown
process.on('SIGTERM', () => {
  logger.info('SIGTERM received, shutting down gracefully');
  process.exit(0);
});

process.on('SIGINT', () => {
  logger.info('SIGINT received, shutting down gracefully');
  process.exit(0);
});
