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


    import android.content.Context
    import androidx.lifecycle.LiveData
    import androidx.lifecycle.MutableLiveData
    import es.verdnatura.domain.GetClaimUserCase
    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.Call
    import retrofit2.Callback
    import retrofit2.Response

class ClaimViewModel(context: Context) : BaseViewModel() {

        private val GetClaimUserCase: GetClaimUserCase = GetClaimUserCase(context)


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



        fun itemShelving_addByClaim(usuario:String,password:String,claimFK:String,shelvingFK:String){
            GetClaimUserCase.itemShelving_addByClaim(usuario,password,claimFK,shelvingFK).enqueue(object : Callback<Void>{
                override fun onFailure(call: Call<Void>, t: Throwable) {

                    _responseadd.value = ResponseItemVO(isError = true,errorMessage = getMessageFromAllResponse(
                        nameofFunction(this),t.message!!)
                    )
                }

                override fun onResponse(call: Call<Void>, response: Response<Void>) {

                    if (!response.isSuccessful){
                        _responseadd.value = ResponseItemVO(isError = true,errorMessage = getMessageFromAllResponse(nameofFunction(this),response.message()))
                    }else{
                        _responseadd.value = ResponseItemVO(isError = false,errorMessage = getMessageFromAllResponse(nameofFunction(this),response.message()))
                    }


                }



            })
        }

       /* fun messageError(message: String,call: String ): ResponseItemVO? {
            return ResponseItemVO(
                isError = true,
                errorMessage = "Error al llamar a " + call + " . Descripción del error:" + message
            )
        }*/


    }
