package com.yidian.common.http

import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

class ApiAddHeadersInterceptor: Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder: Request.Builder = chain.request().newBuilder()
        HttpCommonParamsUtils.androidId?.let {
            builder.addHeader("androidID", it)
        }
        builder.addHeader("app", HttpCommonParamsUtils.cycleId)
        HttpCommonParamsUtils.version?.let {
            builder.addHeader("appVersion", it)
        }
        HttpCommonParamsUtils.deviceId?.let {
            builder.addHeader("device", it)
        }
        HttpCommonParamsUtils.deviceFinger?.let {
            builder.addHeader("ftdf", it)
        }
        HttpCommonParamsUtils.mid?.let {
            builder.addHeader("mid", it)
        }
        HttpCommonParamsUtils.imei?.let {
            builder.addHeader("imei", it)
        }
        builder.addHeader("pkgName", HttpCommonParamsUtils.packageName)
        builder.addHeader("portal", HttpCommonParamsUtils.portal)
        HttpCommonParamsUtils.serialNumber?.let {
            builder.addHeader("serialNumber", it)
        }
        HttpCommonParamsUtils.androidId?.let {
            builder.addHeader("androidID", it)
        }
        builder.addHeader("ver", HttpCommonParamsUtils.currentVersion)
        builder.addHeader("targetSdkVersion", HttpCommonParamsUtils.targetSdkVersion.toString())
        HttpCommonParamsUtils.OS?.let {
            builder.addHeader("cuttOs", it)
        }
        builder.addHeader("token", HttpCommonParamsUtils.token)
        builder.addHeader("X-OC-SESSION", HttpCommonParamsUtils.token)
        builder.addHeader("X-Oc-Merchant-Id", "1qaz2wsx")
        HttpCommonParamsUtils.x_digest?.let {
            builder.addHeader("x-digest", it)
        }
        HttpCommonParamsUtils.sign?.let {
            builder.addHeader("Sign", it)
        }


        return chain.proceed(builder.build())
    }
}