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

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.view.feature.diadeventa.model.ItemShelvingSaleDate
import es.verdnatura.presentation.view.feature.diadeventa.model.ItemShelvingSaleDateList
import retrofit2.Response

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

    private val _itemShelvingSaleDateList by lazy { MutableLiveData<ItemShelvingSaleDateList>() }
    val itemShelvingSaleDateList: LiveData<ItemShelvingSaleDateList>
        get() = _itemShelvingSaleDateList


    fun itemShelvingGetSaleDate(vShelvingFK: String) {
        salix.itemShelvingGetSaleDate(params = listOf(vShelvingFK).formatWithQuotes())
            .enqueue(object : SalixCallback<List<ItemShelvingSaleDate>>(context) {

                override fun onSuccess(response: Response<List<ItemShelvingSaleDate>>) {

                    _itemShelvingSaleDateList.value = response.body()?.let {
                        ItemShelvingSaleDateList(it)
                    }

                }

            })
    }

    fun setParking(scanItem: String, parking: String) {
        salix.setParking(arrayListOf(scanItem, parking).formatWithQuotes())
            .enqueue(object : SalixCallback<Any>(context) {})
    }

}








