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

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import es.verdnatura.domain.SilexCallback
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.base.getMessageFromAllResponse
import es.verdnatura.presentation.base.nameofFunction
import es.verdnatura.presentation.common.ResponseItemVO
import retrofit2.Response


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


    private val _responsescan by lazy { MutableLiveData<ResponseItemVO>() }
    val responsescan: LiveData<ResponseItemVO>
        get() = _responsescan


    fun cmrExpeditionPallet_add(vExpeditionPallet: Int, cmrFk: Int) {
        silex.cmrExpeditionPallet_add(vExpeditionPallet, cmrFk)
            .enqueue(object : SilexCallback<Unit>(context) {
                override fun onError(t: Throwable) {
                    _responsescan.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                    )
                }

                override fun onSuccess(response: Response<Unit>) {

                    _responsescan.value =
                        ResponseItemVO(isError = false, response = response.message()!!)
                }


            })
    }


}