package es.verdnatura.presentation.view.feature.ticket.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 es.verdnatura.presentation.common.packingSiteSalix
import retrofit2.Response

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


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


    fun ticket_advancePackaging(
        ticketFk: Int,
        workerFk: Int

    ) {

        salix.ticket_advancePackaging(packingSiteSalix(ticketFk, workerFk))
            .enqueue(object : SilexCallback<Unit>(context) {

                override fun onError(t: Throwable) {
                    _response.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                    )
                }

                override fun onSuccess(response: Response<Unit>) {
                    _response.value =
                        ResponseItemVO(isError = false, response = response.message())
                }

            })
    }


}
