package com.xty.network

import android.util.Log
import com.tencent.mmkv.MMKV
import com.xty.network.utils.NetWorkLogUtils
import com.youth.banner.util.LogUtils
import okhttp3.Interceptor
import okhttp3.Response

/**
 * 拦截器
 */
class TokenIntercept:Interceptor {
    val mmkv by lazy { MMKV.defaultMMKV() }
    override fun intercept(chain: Interceptor.Chain): Response {
        var request=chain.request()
        val newBuilder = request.newBuilder()
        mmkv!!.decodeString("Auth-Token")?.let {
            NetWorkLogUtils.e("token", "${mmkv!!.decodeString("Auth-Token")!!} "  )
            NetWorkLogUtils.e("token_id", "${mmkv!!.decodeString("Auth-Id")!!} "  )
            NetWorkLogUtils.e("mac_address", MyRetrofit.get().BLUETOOTH_MAC  )
            newBuilder.header("auth-token",mmkv!!.decodeString("Auth-Token")!!)
            newBuilder.header("auth-id",mmkv!!.decodeString("Auth-Id")!!)
            newBuilder.header("mark",MyRetrofit.get().BLUETOOTH_MAC)
        }
        //newBuilder.header("company", Const.COMPANY)
        newBuilder.addHeader("Content-Type", "application/json; charset=utf-8")
        val build = newBuilder.build()
        return  chain.proceed(build)
    }
}