package com.zxhl.cms.utils

import com.zxhl.cms.localmodle.EventBusUpdateXinDongZhiBean
import com.zxhl.cms.net.ApiClient.chatApi
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.chat.ChatMessageChargeOrNotEntity
import org.greenrobot.eventbus.EventBus

/**
 *
 * @Description:     发送消息收费相关
 * @Author:         lidandan
 * @CreateDate:     2021/12/29 3:48 下午
 */
object ChatMessageChargeUtils {
    //首页下拉
    const val MESSAGE_HOME_PULL = 0

    //查看访客
    const val MESSAGE_VISITOR = 1

    //喜欢我
    const val MESSAGE_LIKE_ME = 2

    //查看距离
    const val MESSAGE_LOOK_DISTANCE = 3

    //查看用户主页
    const val MESSAGE_LOOK_USER_HOME = 4

    //超级喜欢
    const val MESSAGE_SUPER_LOVE = 5

    //普通聊天
    const val MESSAGE_NORMAL_TEXT = 6

    //语音聊天
    const val MESSAGE_CALL_CHAT = 7
    //星座匹配
    const val MESSAGE_CONSETLLATION_MACH=7
    /**
     * 查询是否扣费和扣费配置
     */
    fun getChatMessageChargeOrNot(
        type: String,
        userId: String?,
        callback: ChatCallback<ChatMessageChargeOrNotEntity>?
    ) {
        chatApi.getChatMessageChargeOrNot(type, userId)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<ChatMessageChargeOrNotEntity>() {

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    callback?.onError(code, errorMsg)
                }

                override fun onSuccess(result: ChatMessageChargeOrNotEntity?) {
                    result?.let {
                        callback?.onResult(it)
                    }
                }

            })
    }

    fun freeReport(type: Int) {
        chatApi.freeReport(type).compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<Any>() {

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {

                }

                override fun onSuccess(result: Any?) {
                    UserDataUtils.updateUserInfo(null)
                }

            })
    }

    /**
     * 进行扣费
     * @param type 0 首页下拉；1查看访客； 2查看喜欢我；3查看距离；4 查看用户主页； 5超级喜欢 6 聊天 7 语音聊天
     */
    fun chatImDEduction(talkTime: String?, type: String, callback: ChatCallback<String>?) {
        chatApi.chatImDEduction(talkTime, type).compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<Any>() {

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    callback?.onError(code, errorMsg);
                }

                override fun onSuccess(result: Any?) {
                    callback?.onResult("111")
                }

            })
    }

//    /**
//     * 发送消息
//     * @param free 0 免费 1 付费 ；默认值 0
//     */
//    fun chatSendMessage(free: Int, msgContent: String?, msgType: String?, recivierId: String) {
//        chatApi.chatSendMessage(free, msgContent, msgType, recivierId)
//            .compose(RxSchedulers.observableIO2Main()).subscribe(object : BaseObserver<Any>() {
//            override fun onSuccess(result: Any?) {
//                EventBus.getDefault().post(EventBusUpdateXinDongZhiBean())
//            }
//
//            override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
//            }
//
//        })
//    }
}