package com.gh.ndownload

import android.os.Build
import android.text.TextUtils
import com.lg.download.httpclient.DefaultHttpClient
import com.lightgame.download.HttpDnsManager

class NHttpClient : DefaultHttpClient() {

    override fun addHeader(url: String?, meta: HashMap<String, String>?) {
        super.addHeader(url, meta)

        mConnection.setRequestProperty(HttpDnsManager.APP_VERSION, HttpDnsManager.metaMap[HttpDnsManager.APP_VERSION])
        mConnection.setRequestProperty(HttpDnsManager.CHANNEL, HttpDnsManager.metaMap[HttpDnsManager.CHANNEL])
        mConnection.setRequestProperty(HttpDnsManager.GID, HttpDnsManager.metaMap[HttpDnsManager.GID])
        mConnection.setRequestProperty(HttpDnsManager.USER_ID, HttpDnsManager.metaMap[HttpDnsManager.USER_ID])
        mConnection.setRequestProperty(HttpDnsManager.IMEI, HttpDnsManager.metaMap[HttpDnsManager.IMEI])
        mConnection.setRequestProperty(HttpDnsManager.OAID, HttpDnsManager.metaMap[HttpDnsManager.OAID])
        mConnection.setRequestProperty(HttpDnsManager.TOKEN, HttpDnsManager.metaMap[HttpDnsManager.TOKEN])
        mConnection.setRequestProperty(HttpDnsManager.IS_OVERWRITE, HttpDnsManager.metaMap[HttpDnsManager.IS_OVERWRITE])
        mConnection.setRequestProperty(HttpDnsManager.INSTALL_TYPE, HttpDnsManager.metaMap[HttpDnsManager.INSTALL_TYPE])
        mConnection.setRequestProperty(HttpDnsManager.ANDROID_ID, HttpDnsManager.metaMap[HttpDnsManager.ANDROID_ID])
        mConnection.setRequestProperty(
            HttpDnsManager.ANDROID_SDK_VERSION,
            HttpDnsManager.metaMap[HttpDnsManager.ANDROID_SDK_VERSION]
        )
        mConnection.setRequestProperty(HttpDnsManager.REFERER, HttpDnsManager.DEFAULT_REFERER)
        mConnection.setRequestProperty("androidmodel", Build.MODEL)

        val isEmulator = meta?.get("is_emulator")
        val isForcedRealName = meta?.get("force_real_name")
        if (!TextUtils.isEmpty(isForcedRealName) && "false" == isForcedRealName) {
            mConnection.setRequestProperty("force", isForcedRealName)
        }
        if (!TextUtils.isEmpty(isEmulator)) {
            mConnection.setRequestProperty("simulator", isEmulator)
        }
    }

}