package com.zj365.mime.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.common.util.CommonUtils
import com.xty.network.model.MessageBean
import com.xty.network.model.MessageTypeDataBean
import com.xty.network.model.RespBody
import org.json.JSONObject

class MessageVm : BaseVm(){
    val messageLive by lazy{MutableLiveData<RespBody<MessageTypeDataBean>>()}
    val readLive by lazy{MutableLiveData<RespBody<Any>>()}
    val deleteLive by lazy{MutableLiveData<RespBody<Any>>()}
    val deletesLive by lazy { MutableLiveData<RespBody<Any>>() }
    fun getMessageList(page:Int,type:Int){
        startHttp {
            var json=JSONObject()
            json.put("type",type)
            json.put("pageNum",  page)
            json.put("pageSize",20)

            var respnse=apiInterface().getMessageListForType(retrofits.getRequestBody(json.toString()))
            respnse.getCodeStatus(messageLive,nowData)
        }
    }
    ///customer/message
    fun readMsg(id: String, notifyId: String){
        startHttp {
            var json=JSONObject()
            json.put("id", id)

            var respnse=apiInterface().setMessageRead(retrofits.getRequestBody(json.toString()))
            respnse.getCodeStatus(readLive,nowData)
        }
    }

    /**
     * 删除消息
     */
    fun deleteMsg(id:String){
        startHttp {
           var body= apiInterface().deleteMsg(id)
            body.getCodeStatus(deleteLive,nowData)
        }
    }

    fun deleteMsgs(ids:String){
        startHttp {
            var json=JSONObject()
            json.put("id", ids)
            var body= apiInterface().deleteMsgs(retrofits.getRequestBody(json.toString()))
            body.getCodeStatus(deletesLive,nowData)
        }
    }
}