package com.ym.modulecommon.net;

import com.ym.modulecommon.AppLibraryConfig
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**
 * Created by gaoleichao on 2018/5/2.
 *  不拼接参数上报
 */
object  EventApiClient2 {

    private val logInterceptor = HttpLoggingInterceptor()

    private val httpClient = okhttp3.OkHttpClient.Builder()
        .connectTimeout(10000, TimeUnit.MILLISECONDS)
        .readTimeout(10000, TimeUnit.MILLISECONDS)
        .addInterceptor(logInterceptor.apply {
            level =  if(AppLibraryConfig.NetConfig.isDebug)HttpLoggingInterceptor.Level.BODY else{HttpLoggingInterceptor.Level.NONE}
        })
        .hostnameVerifier { hostname, session ->
            true
        }
        .retryOnConnectionFailure(false)
        .build()!!

    private val retrofit = retrofit2.Retrofit.Builder()
        .client(httpClient)
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .addConverterFactory(GsonConverterFactory.create())
        .baseUrl(NetConfig.URL_REPORT_BASE)
        .build()

    val adApi by lazy { retrofit.create(ZXAdApi::class.java) }

}