package com.img.rabbit.viewmodel

import android.content.Context
import com.img.rabbit.bean.response.ServiceWxLinkEntity
import com.img.rabbit.provider.api.ApiManager
import com.tencent.mm.opensdk.constants.Build
import com.tencent.mm.opensdk.modelbiz.WXOpenCustomerServiceChat
import com.tencent.mm.opensdk.openapi.IWXAPI

class MineViewModel : BaseViewModel() {
    private val TAG = "MineViewModel"

    //请求客服连接
    fun requestServiceLink(context: Context,api: IWXAPI){
        mLaunch {
            val response = ApiManager.serviceVo.wxService()
            if (response.status) {
                contactClientService(response.data,context,api)
            } else {
            }
            isLoading.value = false // 加载完成
        }
    }

    private fun contactClientService(data: ServiceWxLinkEntity,context: Context,api: IWXAPI) {
        if (api.wxAppSupportAPI >= Build.SUPPORT_OPEN_CUSTOMER_SERVICE_CHAT) {
            val req = WXOpenCustomerServiceChat.Req()
            req.corpId = data.corpid
            req.url = data.address
            api.sendReq(req)
        }
    }
}