package com.develop.food.base.api

import com.blankj.utilcode.util.AppUtils
import com.develop.food.base.common.API_TOKEN
import com.develop.food.base.http.BaseInterceptor
import com.develop.food.base.utils.MmkvUtils
import com.develop.food.base.utils.getSN
import okhttp3.Interceptor
import okhttp3.Response

class FoodInterceptor : BaseInterceptor() {
    private val requestPath = ""
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val token = MmkvUtils.getString(API_TOKEN) ?: ""
        val builder = request.newBuilder()
            .addHeader("sn", getSN())
            .addHeader("apkVersion", AppUtils.getAppVersionName())
            .addHeader("mcuVersion", "1.0")
            .addHeader("Connection","close")
        if (request.url.toUri().path != requestPath) {
            builder.addHeader("token", token)
        }
        val newRequest = builder.build()
        return chain.proceed(newRequest)

    }
}