package es.verdnatura.presentation.view.feature.claim.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.base.getMessageFromAllResponse
import es.verdnatura.presentation.base.nameofFunction
import es.verdnatura.presentation.common.ResponseItemVO
import retrofit2.Response

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

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

    fun itemShelvingAddByClaim(claimFK: Int, shelvingFK: String) {
        salix.itemShelvingAddByClaim(arrayListOf(claimFK, shelvingFK).formatWithQuotes())
            .enqueue(object : SalixCallback<Unit>(context) {
                override fun onSuccess(response: Response<Unit>) {

                    _responseadd.value = ResponseItemVO(
                        isError = false,
                        errorMessage = getMessageFromAllResponse(
                            nameofFunction(this),
                            response.message()
                        )
                    )
                    super.onSuccess(response)
                }

            })
    }

}
