/**
 * 伺服器端呼叫本機 WS HTTP 推播的 base URL。
 * 開發環境固定走 127.0.0.1，避免 .env 的 WS_HOST 指到遠端導致推播收不到。
 */
export function resolveWsNotifyUserUrl(): string {
    const explicit = process.env.WS_NOTIFY_URL?.trim()
    if (explicit) {
        const base = explicit.replace(/\/$/, '')
        return base.endsWith('/notify-user') ? base : `${base}/notify-user`
    }

    const wsPort = process.env.WS_PORT || '3001'
    if (process.env.NODE_ENV === 'development') {
        return `http://127.0.0.1:${wsPort}/notify-user`
    }

    const wsHost = process.env.WS_HOST || 'localhost'
    return `http://${wsHost}:${wsPort}/notify-user`
}
