package com.amz.genie.services

import okhttp3.Interceptor
import okhttp3.Response

class HeaderInterceptor(
    private val tokenRepo: TokenRepository
) : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val original = chain.request()
        val b = original.newBuilder()
            .header("Content-Type", "application/json")

        val access = tokenRepo.getAccessToken()
        if (!access.isNullOrBlank()) {
            b.header("Authorization", access)
        }

        return chain.proceed(b.method(original.method, original.body).build())
    }
}