package com.kaixed.kchat.network

import com.kaixed.kchat.network.interceptor.SignInterceptor
import com.kaixed.kchat.network.service.ContactService
import com.kaixed.kchat.network.service.UserApiService
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 * @Author: kaixed
 * @Date: 2024/11/15 11:05
 */
object RetrofitClient {

    private const val BASE_URL = "https://app.kaixed.com/kchat/"
//    private const val BASE_URL = "http://192.168.156.209:6196/"

    private val loggingInterceptor = HttpLoggingInterceptor().apply {
        level = HttpLoggingInterceptor.Level.BODY
    }

    private val client = OkHttpClient.Builder()
        .addInterceptor(loggingInterceptor)
//        .addInterceptor(SignInterceptor()) // 添加签名拦截器
        .build()


    private val retrofit: Retrofit by lazy {
        Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .client(client)
            .build()
    }

    val userApiService: UserApiService by lazy {
        retrofit.create(UserApiService::class.java)
    }

    val contactApiService: ContactService by lazy {
        retrofit.create(ContactService::class.java)
    }
}
