package com.zswc.creativity.vmodel

import android.app.Application
import android.graphics.Color
import androidx.lifecycle.viewModelScope
import com.hwangjr.rxbus.RxBus
import com.zswc.creativity.config.ConfigRx
import com.zswc.creativity.utils.net.NetEngine
import com.ysnows.base.base.BRRepository
import com.ysnows.base.base.BRViewModel
import com.ysnows.base.net.IResp
import kotlinx.coroutines.launch

/**
 *Created by shihuiyun
 *on 2020/9/25
 */
class MsgVModel(application: Application) : BRViewModel<BRRepository>(application) {


//    fun toDetails(data_id:String){
//
//        UiSwitch.bundle(repository().context, ArticleDetailActivity::class.java, Bundle().apply {
//            putInt("type",-1)
//            putString("id",data_id)
//        })
//
//
//    }


    fun isRedColor(isRead: Boolean): Int {
        if (isRead) {
            return Color.parseColor("#777777")
        }
        return Color.parseColor("#222222")

    }


    override fun apiFunc(): suspend () -> IResp<*> {
        return { NetEngine.service.msgListPage(10,repository().page) }
    }


    fun isRead(data_id: String) {

        viewModelScope.launch {

            var it = repository().lreq { NetEngine.service.msgRead(data_id) }
            if (it.ok()) {
                //刷新我的界面-消息数量
                RxBus.get().post(ConfigRx.REFRESH_USER_DATA, "")
            }

        }
    }
}
