package com.abbidot.tracker.vm

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.abbidot.baselibrary.constant.MMKVKey
import com.abbidot.baselibrary.util.MMKVUtil
import com.abbidot.tracker.bean.NotificationBean
import com.abbidot.tracker.retrofit2.NetworkApi
import kotlinx.coroutines.launch

/**
 *Created  by .yzq on 2024/9/26/026.
 * @link
 * @description:
 */
class AppSetViewModel : ViewModel() {

    val mGetNotificationLiveData = MutableLiveData<Result<MutableList<NotificationBean>>>()
    val mSetNotificationLiveData = MutableLiveData<Result<String>>()

    /**
     * 获取通知设置
     */
    fun getNotificationSet() {
        viewModelScope.launch {
            val userId = MMKVUtil.getString(MMKVKey.UserId)
            val result = NetworkApi.getNotificationSet(userId)
            mGetNotificationLiveData.value = result
        }
    }

    /**
     * 消息通知设置
     */
    fun setNotification(notificationType: Int, status: Int) {
        viewModelScope.launch {
            val userId = MMKVUtil.getString(MMKVKey.UserId)
            val result = NetworkApi.setNotification(userId, notificationType, status)
            mSetNotificationLiveData.value = result
        }
    }
}