/**
 * 净水机小程序环境（仅本小程序）
 *
 * APP_ENV:
 *   local — 本机 8120（需开发者工具勾选「不校验合法域名」）
 *   test  — 测试网关
 *   prod  — 生产网关（正式版 / 体验版发版必须用 prod）
 *
 * 静态资源：统一 https://static.hshuishang.com
 */
const APP_ENV = 'local' // local | test | prod（正式/体验版必须 prod；本机联调改为 local）

const STATIC_URL = 'https://static.hshuishang.com'
const ALIYUN_OSS_URL = 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com'

const API = {
  local: {
    server_url: 'http://127.0.0.1:8120/api/v1',
    api_host: 'http://127.0.0.1:8120',
  },
  test: {
    server_url: 'https://test.hshuishang.com/api/v1',
    api_host: 'https://test.hshuishang.com',
  },
  prod: {
    server_url: 'https://api.hshuishang.com/api/v1',
    api_host: 'https://api.hshuishang.com',
  },
}

if (!API[APP_ENV]) {
  throw new Error('config/env.js: APP_ENV must be local|test|prod, got ' + APP_ENV)
}

const api = API[APP_ENV]
const USE_LOCAL = APP_ENV === 'local'

module.exports = {
  APP_ENV,
  USE_LOCAL,
  STATIC_URL,
  CDN: {
    development: { static_url: STATIC_URL, aliyun_oss_url: ALIYUN_OSS_URL },
    production: { static_url: STATIC_URL, aliyun_oss_url: ALIYUN_OSS_URL },
  },
  ENV: {
    local: { ...API.local, static_url: STATIC_URL, aliyun_oss_url: ALIYUN_OSS_URL },
    test: { ...API.test, static_url: STATIC_URL, aliyun_oss_url: ALIYUN_OSS_URL },
    prod: { ...API.prod, static_url: STATIC_URL, aliyun_oss_url: ALIYUN_OSS_URL },
  },
  server_url: api.server_url,
  img_url: api.api_host,
  static_url: STATIC_URL,
  aliyun_oss_url: ALIYUN_OSS_URL,
}
