package com.mogo.cloud.network.interceptor

import com.mogo.cloud.passport.MoGoAiCloudClient
import okhttp3.Interceptor
import okhttp3.Response

/**
 * created by wujifei on 2021/1/20 15:18
 * describe:header携带信息
 */
class HttpHeaderInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val original = chain.request()
        var request = original.newBuilder()
                .header("token", MoGoAiCloudClient.getInstance().aiCloudClientConfig.token)
                .header("cityCode", MoGoAiCloudClient.getInstance().aiCloudClientConfig.iHttpCurrentLocation.currentLocation?.cityCode.toString())
                .header("lat",MoGoAiCloudClient.getInstance().aiCloudClientConfig.iHttpCurrentLocation.currentLocation?.lat.toString())
                .header("lon",MoGoAiCloudClient.getInstance().aiCloudClientConfig.iHttpCurrentLocation.currentLocation?.lon.toString())
                .header("env",MoGoAiCloudClient.getInstance().aiCloudClientConfig.netMode.toString())
                .header("sn",MoGoAiCloudClient.getInstance().aiCloudClientConfig.sn)
                .method(original.method(), original.body())
                .build()
        if(MoGoAiCloudClient.getInstance().aiCloudClientConfig.securityKey.isNotBlank()){
            request = request.newBuilder().header("authKey",MoGoAiCloudClient.getInstance().aiCloudClientConfig.securityKey).build()
        }
        return chain.proceed(request)
    }
}