let runtimeConfig = {}

try {
    runtimeConfig = require(`${__hooks}/bai_api_pb_hooks/bai_api_shared/config/runtime.js`)
} catch (_err) {
    runtimeConfig = {}
}

function pick(key, fallback) {
    const envValue = $os.getenv(key)
    if (envValue !== '') return envValue

    if (runtimeConfig && typeof runtimeConfig[key] !== 'undefined' && runtimeConfig[key] !== '') {
        return runtimeConfig[key]
    }

    return fallback
}

module.exports = {
    nodeEnv: pick('NODE_ENV', 'production'),
    apiPrefix: '/api',
    appVersion: pick('APP_VERSION', 'dev-local'),
    wechatAppId: pick('WECHAT_APPID', ''),
    wechatSecret: pick('WECHAT_SECRET', ''),
    pocketbaseApiUrl: pick('POCKETBASE_API_URL', ''),
    pocketbaseAuthToken: pick('POCKETBASE_AUTH_TOKEN', ''),
    appBaseUrl: pick('APP_BASE_URL', ''),
    buildTime: pick('BUILD_TIME', null),
}
