package com.ym.chat.presenter

import android.util.Log
import com.ym.chat.contract.SystemMessageContract
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.chat.ChatMessageEntity

class SystemMsgPresenter : SystemMessageContract.Presenter {

    private val mView: SystemMessageContract.View


    constructor(mView: SystemMessageContract.View) {
        this.mView = mView
    }
    override fun getmsgLog(lastMsgKey: String, userId: String) {
        ApiClient.homeApi.getMessageLosg(lastMsgKey, userId)
            .compose(RxSchedulers.observableIO2Main())
            .subscribe(object : BaseObserver<ChatMessageEntity>() {
                override fun onSuccess(result: ChatMessageEntity?) {
                        if(result!=null){
                            mView.setData(result)
                        }else{
                            mView.setEmptyView()
                        }

                }

                override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
                    mView.setEmptyView()
                    Log.e("MXL", "ERROR" + code + errorMsg)
                }
            })
    }
}