package com.lukouguoji.module_base.http.net

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.lukouguoji.module_base.http.net.Api
import com.lukouguoji.module_base.http.user.SelfLoginInterceptor
import com.lukouguoji.module_base.http.user.StringConverterFactory
import com.lukouguoji.module_base.impl.HttpLogImpl
import dev.utils.DevFinal
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
import kotlin.properties.Delegates

/**
 * @author ：Martin
 * @data : 2018/6/21 15:39
 */
object StringNetApply {

    // 超时时间
    private const val DEFAULT_TIMEOUT: Long = 30000L

    //  接口对象
    var api: ApiString by Delegates.notNull()

    init {
        // 初始化OkHttp
        val client = OkHttpClient.Builder()
            // 连接超时时间
            .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
            // 读取超时时间
            .readTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
            // 写入超时时间
            .callTimeout(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS)
            .build()

        // 初始化Retrofit
        val retrofit = Retrofit.Builder()
            // 设置OkHttp
            .client(client)
            // 设置网络请求的Url地址
            .baseUrl(ApiString.BASE_URL)
            .addConverterFactory(StringConverterFactory.create())
            .build()

        api = retrofit.create(ApiString::class.java)
    }

}