const { Sequelize } = require('sequelize');
const logger = require('./logger');
const config = require('../config/database');

const env = process.env.NODE_ENV || 'development';
const dbConfig = config[env];

const sequelize = new Sequelize(dbConfig);

sequelize.authenticate()
  .then(() => logger.info('Database connection established'))
  .catch(err => logger.error('Database connection failed:', err));

module.exports = sequelize;