package com.sambath.kunkhmer.screen.report

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.sambath.kunkhmer.base.BaseViewModel
import com.sambath.kunkhmer.remote.service.ApiService
import com.sambath.kunkhmer.util.PrefHelper

class StatementViewModel (val apiService: ApiService, val prefHelper: PrefHelper): BaseViewModel() {
    private val _state = MutableLiveData<StatementViewState>(StatementViewState())
    val state: LiveData<StatementViewState> = _state
    fun getStatementData(){
//        if (_state.value!!.isProgress) return
//        _state.value = prev().copy(isProgress = true)
//        disposables.add(
//            apiService.getStatementData()
//                .timeout(60, TimeUnit.SECONDS)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe({
//                    if (it.resultCode == "1") {
////                        Log.d("dataxzsd", it.data.toString())
//                        _state.value = prev().copy(
//                            isProgress = false,
//                            error = null,
//                            statementList = it.data?.statementList
//                        )
//                    } else {
//                        _state.value =
//                            prev().copy(isProgress = false, error = "[${it.message.description}]")
//                    }
//                }, {
////                    Log.d("dataxzsd", it.getErrorCode())
//                    val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.getErrorCode()
//                    _state.value = prev().copy(isProgress = false, error = message)
//                })
//        )
    }

    private fun prev() = _state.value!!
}