package com.doverfuelingsolutions.issp.api.basic

import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitUtil {

    private val loggingInterceptor: LoggingInterceptor by lazy { LoggingInterceptor() }
    private val authInterceptor: AuthInterceptor by lazy { AuthInterceptor() }
    private val basicHttpBuilder: OkHttpClient.Builder by lazy { OkHttpClient.Builder().addInterceptor(loggingInterceptor) }
    private val authHttpBuilder: OkHttpClient.Builder by lazy {
        OkHttpClient.Builder()
            .addInterceptor(loggingInterceptor)
            .addInterceptor(authInterceptor)
    }

    private val mGsonConverterFactory: GsonConverterFactory by lazy { GsonConverterFactory.create() }

    fun getGsonBuilder(): Retrofit.Builder {
        return Retrofit.Builder()
            .addConverterFactory(mGsonConverterFactory)
            .client(basicHttpBuilder.build())
    }

    fun getAuthBuilder(): Retrofit.Builder {
        return Retrofit.Builder()
            .addConverterFactory(mGsonConverterFactory)
            .client(authHttpBuilder.build())
    }
}