package com.github.hd97300.keddit.data.network.interceptors

import com.github.hd97300.keddit.data.auth.AuthHolder
import okhttp3.Interceptor
import okhttp3.Response

abstract class AuthorizationHeaderInterceptor : Interceptor {
    protected abstract val headerValue: String

    override fun intercept(chain: Interceptor.Chain): Response {
        return chain.proceed(chain.request().newBuilder()
                .header("Authorization", headerValue)
                .build())
    }
}

class BearerAuthHeaderInterceptor(private val authHolder: AuthHolder) : AuthorizationHeaderInterceptor() {
    override val headerValue: String
        get() = "Bearer ${authHolder.access}"
}

class BasicAuthHeaderInterceptor(override val headerValue: String) : AuthorizationHeaderInterceptor()