package com.adealink.weparty.config.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.adealink.frame.mvvm.viewmodel.BaseViewModel
import com.adealink.weparty.config.IApprovingVersionListener
import com.adealink.weparty.config.approvingVersionManager

class ApprovingVersionViewModel : BaseViewModel(), IApprovingVersionListener {

    val approvingLD: LiveData<Boolean> = MutableLiveData()

    init {
        approvingVersionManager.addListener(this)
        approvingLD.send(approvingVersionManager.isApproving())
    }

    override fun onCleared() {
        super.onCleared()
        approvingVersionManager.removeListener(this)
    }

    fun refreshApproving() {
        approvingVersionManager.refreshApproving()
    }

    override fun onApprovingChanged(enable: Boolean) {
        super.onApprovingChanged(enable)
        approvingLD.send(approvingVersionManager.isApproving())
    }

}