package com.rc.httpcore.interceptor

import android.annotation.SuppressLint
import android.util.Log
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.LogUtils
import okhttp3.Interceptor
import okhttp3.Response
import okhttp3.ResponseBody
import okio.Buffer
import org.json.JSONObject
import java.io.IOException

class ParameterValidationInterceptor : Interceptor {
    companion object {
        private const val TAG = "ParameterValidationInterceptor"
    }

    @SuppressLint("LongLogTag")
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        LogUtils.json(request)

        // 继续处理请求
        val response = chain.proceed(request)

        // 读取响应体
        val responseBody = response.body()
        val responseBodyString = responseBody?.string() ?: ""

        LogUtils.d(response.toString(), responseBodyString)
        // 创建一个新的响应体，以便返回
        return response.newBuilder()
            .body(ResponseBody.create(responseBody?.contentType(), responseBodyString))
            .build()
    }


}