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

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
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.buscaritem.model.ItemLocationVO
import es.verdnatura.presentation.view.feature.buscaritem.model.LocationListVO
import retrofit2.Response

class BuscarItemViewModel(val context: Context) : BaseViewModel(context) {
    private val _locationList by lazy { MutableLiveData<LocationListVO>() }
    val locationList: LiveData<LocationListVO>
        get() = _locationList
    val loadLocationList: LiveData<Event<LocationListVO>> = _locationList.map { Event(it) }

    fun itemshelvingGetInfo(itemFk: Any) {
        salix.itemshelvingGetInfo(params = arrayListOf(itemFk).formatWithQuotes())
            .enqueue(object : SalixCallback<List<ItemLocationVO>>(context) {
                override fun onSuccess(response: Response<List<ItemLocationVO>>) {
                    _locationList.value = response.body()?.let { LocationListVO(it) }
                }

            })
    }

}
