package com.doverfuelingsolutions.issp.api.basic

import com.doverfuelingsolutions.issp.utils.log.DFSLog
import okhttp3.Interceptor
import okhttp3.Response

class LoggingInterceptor : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val time = System.currentTimeMillis()

//        val requestBuilder = request.newBuilder()
//        requestBuilder.removeHeader("requestName")
//        val newRequest = requestBuilder.build()

        val response = chain.proceed(request)
        val body = response.body()
        val stringBody = if (body == null) "null" else response.peekBody(Long.MAX_VALUE).string()
        DFSLog.v(
            "=====>>>>> request done in ${System.currentTimeMillis() - time}ms",
            "method: ${request.method()}",
            "url: ${request.url()}",
            "code: ${response.code()}",
            "body: $stringBody"
        )
        return response
    }
}