package com.khmer9.yuki.app

import com.khmer9.yuki.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()}"
                request = request.newBuilder()
                    .addHeader("Authorization", "bearer " + finalToken)
                    .build()
            }
        }
        return chain.proceed(request)
    }
}