package com.khmer9.lotto.app

import com.khmer9.lotto.util.PrefHelper
import okhttp3.Interceptor
import okhttp3.Response

class ServiceInterceptor(private val prefHelper: PrefHelper) : Interceptor {

//    var token : String = "";
//
//    fun Token(token: String ) {
//        this.token = token;
//    }

    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()}"
                request = request.newBuilder()
                    .addHeader("Authorization",finalToken)
                    .build()
            }

        }

        return chain.proceed(request)
    }

}