package com.doverfuelingsolutions.issp.api.basic

import com.doverfuelingsolutions.issp.data.DataStore
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", DataStore.sn)
        if (DataStore.accessToken.isNotBlank()) request.header("Authorization", "Bearer ${DataStore.accessToken}")
        if (DataStore.buId.isNotBlank()) request.header("CurrentBuId", DataStore.buId)
        return chain.proceed(request.build())
    }
}