// 环境配置
const path = require('path')
require('dotenv').config({ path: path.join(__dirname, '../../.env') })

const config = {
  // 开发环境
  development: {
    port: process.env.PORT || 3200,
    mysql: {
      host: process.env.DB_HOST || 'nj-cdb-3pwh2kz1.sql.tencentcdb.com',
      port: process.env.DB_PORT || 20784,
      user: process.env.DB_USER || 'jiebanke',
      password: process.env.DB_PASSWORD || 'aiot741$12346',
      database: process.env.DB_NAME || 'jbkdata',
      connectionLimit: 10,
      charset: 'utf8mb4',
      timezone: '+08:00'
    },
    jwt: {
      secret: process.env.JWT_SECRET || 'dev-jwt-secret-key-2024',
      expiresIn: process.env.JWT_EXPIRES_IN || '7d',
      refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES_IN || '30d'
    },

    upload: {
      maxFileSize: 5 * 1024 * 1024, // 5MB
      allowedTypes: ['image/jpeg', 'image/png', 'image/gif']
    },
    cors: {
      origin: process.env.CORS_ORIGIN || 'http://localhost:3150',
      credentials: true
    }
  },

  // 测试环境
  test: {
    port: process.env.PORT || 3110,
    mysql: {
      host: process.env.DB_HOST || 'nj-cdb-3pwh2kz1.sql.tencentcdb.com',
      port: process.env.DB_PORT || 20784,
      user: process.env.DB_USER || 'jiebanke',
      password: process.env.DB_PASSWORD || 'aiot741$12346',
      database: process.env.DB_NAME || 'jbkdata',
      connectionLimit: 5,
      charset: 'utf8mb4',
      timezone: '+08:00'
    },
    jwt: {
      secret: process.env.JWT_SECRET || 'test-jwt-secret-key-2024',
      expiresIn: '1h',
      refreshExpiresIn: '7d'
    },
    upload: {
      maxFileSize: 2 * 1024 * 1024, // 2MB
      allowedTypes: ['image/jpeg', 'image/png']
    }
  },

  // 生产环境
  production: {
    port: process.env.PORT || 3110,
    mysql: {
      host: process.env.DB_HOST || 'nj-cdb-3pwh2kz1.sql.tencentcdb.com',
      port: process.env.DB_PORT || 20784,
      user: process.env.DB_USER || 'jiebanke',
      password: process.env.DB_PASSWORD || 'aiot741$12346',
      database: process.env.DB_NAME || 'jbkdata',
      connectionLimit: 20,
      charset: 'utf8mb4',
      timezone: '+08:00'
    },
    jwt: {
      secret: process.env.JWT_SECRET,
      expiresIn: process.env.JWT_EXPIRES_IN || '1d',
      refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES_IN || '7d'
    },

    upload: {
      maxFileSize: 10 * 1024 * 1024, // 10MB
      allowedTypes: ['image/jpeg', 'image/png', 'image/webp']
    },
    cors: {
      origin: process.env.CORS_ORIGIN || 'https://www.jiebanke.com',
      credentials: true
    }
  }
}

// 获取当前环境配置
const getConfig = () => {
  const env = process.env.NODE_ENV || 'development'
  return config[env]
}

module.exports = getConfig()