package es.verdnatura.presentation.view.feature.historicoshelving.fragment

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.common.Event
import es.verdnatura.presentation.view.feature.historicoshelving.model.ItemShelvingLog
import es.verdnatura.presentation.view.feature.historicoshelving.model.ItemShelvingLogList
import retrofit2.Response

class ItemShelvingLogViewModel(val context: Context) : BaseViewModel(context) {

    private val _itemShelvingLogList by lazy { MutableLiveData<ItemShelvingLogList>() }
    val itemShelvingLogList: LiveData<ItemShelvingLogList>
        get() = _itemShelvingLogList

    val loadItemShelvingLogList = Transformations.map(_itemShelvingLogList) { Event(it) }

    fun itemShelvingLogGet(vShelvingFK: String) {
        //salix falla fecha
        //silex.itemShelvingLog_get(vShelvingFK)
        salix.itemShelvingLogGet(params = listOf(vShelvingFK).formatWithQuotes())
            .enqueue(object :
                SalixCallback<List<ItemShelvingLog>>(context) {
                override fun onSuccess(response: Response<List<ItemShelvingLog>>) {
                    _itemShelvingLogList.value = response.body()?.let {
                        ItemShelvingLogList(it)
                    }
                }

            })
    }

}








