import 'dotenv/config';
import { Options } from 'sequelize';
import { DbConfig } from '../../types/common.types.js';

const config: DbConfig = {
  development: {
    username: process.env.DB_USER || 'laxman',
    password: process.env.DB_PASSWORD || '<.efvP1D0^80Z)r5',
    database: process.env.DB_NAME || 'royal_enfield_onboarding',
    host: process.env.DB_HOST || 'localhost',
    port: parseInt(process.env.DB_PORT || '5432'),
    dialect: 'postgres',
    logging: false,
    pool: {
      max: 5,
      min: 0,
      acquire: 30000,
      idle: 10000
    }
  },
  production: {
    username: process.env.DB_USER || 'laxman',
    password: process.env.DB_PASSWORD || 'Admin@123',
    database: process.env.DB_NAME || 'royal_enfield_onboarding',
    host: process.env.DB_HOST || 'localhost',
    port: parseInt(process.env.DB_PORT || '5432'),
    dialect: 'postgres',
    logging: false,
    pool: {
      max: 20,
      min: 5,
      acquire: 60000,
      idle: 10000
    },
    dialectOptions: {
      ssl: process.env.DB_SSL === 'true' ? {
        require: true,
        rejectUnauthorized: false
      } : false
    }
  },
  test: {
    username: process.env.DB_USER || 'laxman',
    password: process.env.DB_PASSWORD || 'Admin@123',
    database: (process.env.DB_NAME || 'royal_enfield_onboarding') + '_test',
    host: process.env.DB_HOST || 'localhost',
    port: parseInt(process.env.DB_PORT || '5432'),
    dialect: 'postgres',
    logging: false
  }
};

export default config;
