package com.swago.user.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.swago.baseswago.inter.ApiManager
import com.swago.baseswago.model.ConfigModel
import com.swago.baseswago.model.mine.TaskModel
import com.swago.baseswago.util.BaseViewModel

/**
 *@date 2021/11/28 13:03
 *description:
 */
class TaskVm (application: Application) : BaseViewModel(application) {

    val taskListLiveData by lazy {
        MutableLiveData<List<TaskModel>?>()
    }

    val receiveLiveData by lazy {
        MutableLiveData<Int>()
    }

    fun getTaskList(type:Int){
        requestData2 {
            requestData {
                val data = ApiManager.userApi.getTaskList(type)
                taskListLiveData.value  = data
            }
            requestError {
                taskListLiveData.value = null
            }
        }
    }


    fun receiveReward(id:String,position:Int){
        requestData {
            ApiManager.userApi.receiveTaskReward(id)
            receiveLiveData.value = position
        }
    }


    val appConfigLiveData by lazy {
        MutableLiveData<ConfigModel>()
    }
    /**
     * 获取配置
     */
    fun getAppConfig(){
        requestData {
            val data = ApiManager.configApi.getAppConfig()
            appConfigLiveData.value = data
        }
    }
}