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

import android.content.Context
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import es.verdnatura.domain.SalixCallback
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.common.Event
import es.verdnatura.presentation.view.feature.historicoshelvinglog.model.ShelvingLogSalix
import es.verdnatura.presentation.view.feature.historicoshelvinglog.model.ShelvingLogSalixList
import retrofit2.Response

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

    private val _itemShelvingLogSalixList by lazy { MutableLiveData<ShelvingLogSalixList>() }
    val loadShelvingLogSalixList = Transformations.map(_itemShelvingLogSalixList) { Event(it) }

    fun shelvings(vShelvingFK: String) {
        salix.Shelvings("""{"where": {"code": "$vShelvingFK"}}""").enqueue(object :
            SalixCallback<List<ShelvingLogSalix>>(context) {
            override fun onSuccess(response: Response<List<ShelvingLogSalix>>) {
                _itemShelvingLogSalixList.value = response.body()?.let {
                    ShelvingLogSalixList(it)
                }

            }

        })

    }
}








