package com.doverfuelingsolutions.issp.api.basic

import com.doverfuelingsolutions.issp.data.GlobalData
import okhttp3.Interceptor
import okhttp3.Response

class AuthInterceptor : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request().newBuilder()
            .addHeader("Content-Type", "application/json")
            .addHeader("Accept", "application/json")
            .addHeader("DeviceSN", GlobalData.serialNumber.get())
        if (GlobalData.accessToken.get().isNotBlank()) request.header("Authorization", "Bearer ${GlobalData.accessToken.get()}")
        if (GlobalData.businessId.get().isNotBlank()) request.header("CurrentBuId", GlobalData.businessId.get())
        return chain.proceed(request.build())
    }
}