package com.sambath.sbc.app

import com.sambath.sbc.util.PrefHelper
import okhttp3.Interceptor
import okhttp3.Response

class ServiceInterceptor(private val prefHelper: PrefHelper) : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        var request = chain.request()
        if (request.header("No-Authentication") == null) {
            //or use Token Function
            if (prefHelper.getToken().isNotEmpty()) {
                val finalToken = prefHelper.getToken()
                val channelType = prefHelper.getChannelType()
                request = request.newBuilder()
                    .addHeader("Authorization", finalToken)
                    .addHeader("channel-type", channelType.toString())
                    .build()
            }
        }
        return chain.proceed(request)
    }
}