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

import android.content.Context
import android.util.Log
import android.util.Log.d
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import es.verdnatura.domain.GetLoginUserCase
import es.verdnatura.domain.GetPreSacadorUseCase
import es.verdnatura.domain.GetSacadorControladorUserCase
import es.verdnatura.domain.GetUbicadorUserCase
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.view.feature.collection.listSaleSalix
import es.verdnatura.presentation.view.feature.collection.saleSalix
import es.verdnatura.presentation.view.feature.presacador.model.PreSacadorItemVO
import es.verdnatura.presentation.view.feature.sacador.mapper.toDateFormat
import es.verdnatura.presentation.view.feature.sacador.model.CollectionListVO
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyListVO
import es.verdnatura.presentation.view.feature.sacador.model.PlacementSupplyVO
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

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

    private val contextApp=context
    private val getPreSacadorUseCase: GetPreSacadorUseCase = GetPreSacadorUseCase(context)
    private val getSacadorControladorUserCase: GetSacadorControladorUserCase =
        GetSacadorControladorUserCase(context)

    private val getUbicadorUserCase: GetUbicadorUserCase = GetUbicadorUserCase(context)
    private val getLoginUserCase: GetLoginUserCase = GetLoginUserCase(context)

    private val _salesList by lazy { MutableLiveData<List<PreSacadorItemVO>>() }
    val salesList: LiveData<List<PreSacadorItemVO>>
        get() = _salesList

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

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

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

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


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

    private val _placementSuppleyList by lazy { MutableLiveData<PlacementSupplyListVO>() }
    val placementSuppleyList: LiveData<PlacementSupplyListVO>
        get() = _placementSuppleyList

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

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

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

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

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

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

    //sergio: previa nuevo
    private val _collectionList by lazy { MutableLiveData<CollectionListVO>() }
    val collectionList: LiveData<CollectionListVO>
        get() = _collectionList

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

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

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

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


    fun ticketToPrePrepare(usuario: String, password: String, ticketFk: String, sectorFk: String) {
        getPreSacadorUseCase.ticketToPrePrepare(usuario, password, ticketFk, sectorFk)
            .enqueue(object :
                Callback<List<PreSacadorItemVO>> {
                override fun onFailure(call: Call<List<PreSacadorItemVO>>, t: Throwable) {
                    //d("VERDNATURA::", "ha fallado")
                    _salesList.value = listOf()
                }

                override fun onResponse(
                    call: Call<List<PreSacadorItemVO>>,
                    response: Response<List<PreSacadorItemVO>>
                ) {
                    if (response.body() != null) {
                        _salesList.value = response.body()?.let { it }
                    } else {
                        _salesList.value = listOf()
                    }
                }
            })
    }

    fun collectionStickerPrint(
        usuario: String,
        password: String,
        collectionFk: String,
        sectorFk: String
    ) {
        getSacadorControladorUserCase.collectionStickerPrint(
            usuario,
            password,
            collectionFk,
            sectorFk
        ).enqueue(object : Callback<Any> {
            override fun onFailure(call: Call<Any>, t: Throwable) {
                _response.value = ResponseItemVO(
                    isError = true,
                    errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                )
            }

            override fun onResponse(call: Call<Any>, response: Response<Any>) {
                if (!response.isSuccessful) {
                    _response.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(
                            nameofFunction(this),
                            response.message()
                        )
                    )
                } else {
                    _response.value =
                        ResponseItemVO(isError = false, response = response.message()!!)
                }
            }
        })
    }

    fun parking(
        usuario: String,
        password: String,
        ticketFk: String,
        parking: String
    ) {
        getUbicadorUserCase.shelvingPark(usuario, password, ticketFk, parking)
            .enqueue(object : Callback<Any> {
                override fun onFailure(call: Call<Any>, t: Throwable) {
                    _response.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                    )
                }

                override fun onResponse(call: Call<Any>, response: Response<Any>) {
                    if (!response.isSuccessful) {
                        _response.value = ResponseItemVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this),
                                response.message()
                            )
                        )
                    } else {
                        _response.value =
                            ResponseItemVO(isError = false, response = response.message())
                    }
                }
            })
    }


    /* fun saleParking_add(usuario: String, password: String, sales:List<String>,parking: String)
     {
         getUbicadorUserCase.saleParking_add(usuario, password, sales, parking)
             .enqueue(object : Callback<String>
             {
                 override fun onFailure(call: Call<String>, t: Throwable)
                 {
                     _responseParkingAdd.value = ResponseItemVO(
                         isError = true,
                         errorMessage = getMessageFromAllResponse(nameofFunction(this),t.message!!)
                     )
                 }

                 override fun onResponse(call: Call<String>, response: Response<String>)
                 {
                     if (!response.isSuccessfull)
                     {
                         _responseParkingAdd.value = ResponseItemVO(
                             isError = true,
                             errorMessage = getMessageFromAllResponse(nameofFunction(this),response.message())
                         )
                     } else
                     {
                         _responseParkingAdd.value =
                             ResponseItemVO(isError = false, response = response.body()!!)
                     }
                 }
             })
     }*/

    fun itemPlacementSupplyAiming(
        usuario: String,
        password: String,
        shelvingFk: String,
        quantity: String,
        itemFk: String
    ) {
        getSacadorControladorUserCase.itemPlacementSupplyAiming(
            usuario,
            password,
            shelvingFk,
            quantity,
            itemFk
        ).enqueue(object :
            Callback<List<PlacementSupplyVO>> {
            override fun onFailure(call: Call<List<PlacementSupplyVO>>, t: Throwable) {
                val listError: ArrayList<PlacementSupplyVO> = ArrayList()
                listError.add(
                    PlacementSupplyVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                    )
                )
                _placementSuppleyList.value = PlacementSupplyListVO(listError)
            }

            override fun onResponse(
                call: Call<List<PlacementSupplyVO>>,
                response: Response<List<PlacementSupplyVO>>
            ) {
                if (response.body() != null) {
                    _placementSuppleyList.value = response.body()?.let { PlacementSupplyListVO(it) }
                } else {
                    val listError: ArrayList<PlacementSupplyVO> = ArrayList()
                    listError.add(
                        PlacementSupplyVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this),
                                response.message()
                            )
                        )
                    )
                    _placementSuppleyList.value = PlacementSupplyListVO(listError)
                }
            }
        })
    }

    fun itemShelvingSaleSupplyAdd(
        usuario: String,
        password: String,
        itemShelvingFk: String,
        saleFk: String,
        quantity: String
    ) {
        getSacadorControladorUserCase.itemShelvingSaleSupplyAdd(
            usuario,
            password,
            itemShelvingFk,
            saleFk,
            quantity
        ).enqueue(object : Callback<Any> {
            override fun onFailure(call: Call<Any>, t: Throwable) {
                _responseItemShelvingSaleSupplyAdd.value = ResponseItemVO(
                    isError = true,
                    errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                )
            }

            override fun onResponse(call: Call<Any>, response: Response<Any>) {
                if (!response.isSuccessful) {
                    _responseItemShelvingSaleSupplyAdd.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(
                            nameofFunction(this),
                            response.message()
                        )
                    )
                } else {
                    _responseItemShelvingSaleSupplyAdd.value =
                        ResponseItemVO(isError = false, response = response.message())
                }
            }
        })
    }



    fun saleTrackingReplace(
        usuario: String,
        password: String,
        saleFk: String,
        vOriginalQuantity: String,
        vStateFk: String,
        vIsChecked: String,
        vBuyFk: String
    ) {

        getSacadorControladorUserCase.saleTrackingReplace(
            usuario,
            password,
            saleFk,
            vOriginalQuantity,
            vStateFk,
            vIsChecked,
            vBuyFk
        ).enqueue(object : Callback<Any> {
            override fun onFailure(call: Call<Any>, t: Throwable) {
                _response.value = ResponseItemVO(
                    isError = true,
                    errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                )
            }

            override fun onResponse(call: Call<Any>, response: Response<Any>) {
                if (!response.isSuccessful) {
                    _response.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(
                            nameofFunction(this),
                            response.message()
                        )
                    )
                } else {
                    _response.value = ResponseItemVO(isError = false, response = "")
                }
            }
        })
    }

    fun getIdFromCode(usuario: String, password: String, code: String) {
        getSacadorControladorUserCase.getIdFromCode(usuario, password, code)
            .enqueue(object : Callback<String> {
                override fun onFailure(call: Call<String>, t: Throwable) {
                    _responseCode.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                    )
                }

                override fun onResponse(call: Call<String>, response: Response<String>) {
                    //sergio: espera item en el body
                    if (response.body() == null) {
                        _responseCode.value = ResponseItemVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this),
                                response.message()
                            )
                        )

                    } else {
                        _responseCode.value =
                            ResponseItemVO(isError = false, response = response.body()!!)
                    }
                }
            })
    }

    fun saleTrackingDel(usuario: String, password: String, saleFk: String) {
        getSacadorControladorUserCase.saleTrackingDel(usuario, password, saleFk)
            .enqueue(object : Callback<Any> {
                override fun onFailure(call: Call<Any>, t: Throwable) {
                    _response.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                    )
                }

                override fun onResponse(call: Call<Any>, response: Response<Any>) {
                    if (!response.isSuccessful) {
                        _response.value = ResponseItemVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this),
                                response.message()
                            )
                        )
                    } else {
                        _response.value =
                            ResponseItemVO(isError = false, response = response.message())
                    }
                }
            })
    }

    fun saleMove(
        usuario: String,
        password: String,
        saleFk: String,
        quantity: String,
        originalQuantity: String
    ) {
        getSacadorControladorUserCase.saleMove(
            usuario,
            password,
            saleFk,
            quantity,
            originalQuantity
        ).enqueue(object : Callback<Any> {
            override fun onFailure(call: Call<Any>, t: Throwable) {
                _responseSaleMove.value = ResponseItemVO(
                    isError = true,
                    errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                )
            }

            override fun onResponse(call: Call<Any>, response: Response<Any>) {
                if (!response.isSuccessful) {
                    _responseSaleMove.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(
                            nameofFunction(this),
                            response.message()
                        )
                    )
                } else {
                    _responseSaleMove.value =
                        ResponseItemVO(isError = false, response = response.message())
                }
            }
        })
    }

    fun collectionMissingTrash(
        usuario: String,
        password: String,
        saleFk: String,
        quantity: String,
        type: String,
        warehouseFk: String,
        originalQuantity: String
    ) {
        getSacadorControladorUserCase.collectionMissingTrash(
            usuario,
            password,
            saleFk,
            quantity,
            type,
            warehouseFk,
            originalQuantity
        ).enqueue(object : Callback<Any> {
            override fun onFailure(call: Call<Any>, t: Throwable) {
                _responseMissingTrash.value = ResponseItemVO(
                    isError = true,
                    errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                )
            }

            override fun onResponse(call: Call<Any>, response: Response<Any>) {
                if (!response.isSuccessful) {
                    _responseMissingTrash.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(
                            nameofFunction(this),
                            response.message()
                        )
                    )
                } else {
                    _responseMissingTrash.value =
                        ResponseItemVO(isError = false, response = response.message())
                }
            }
        })
    }

    fun collectionIncreaseQuantity(
        usuario: String,
        password: String,
        saleFk: String,
        quantity: String
    ) {
        getSacadorControladorUserCase.collectionIncreaseQuantity(
            usuario,
            password,
            saleFk,
            quantity
        ).enqueue(object : Callback<Any> {
            override fun onFailure(call: Call<Any>, t: Throwable) {
                _responseIncQuantity.value = ResponseItemVO(
                    isError = true,
                    errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                )
            }

            override fun onResponse(call: Call<Any>, response: Response<Any>) {
                if (!response.isSuccessful) {
                    _responseIncQuantity.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(
                            nameofFunction(this),
                            response.message()
                        )
                    )
                } else {
                    _responseIncQuantity.value =
                        ResponseItemVO(isError = false, response = response.message())
                }
            }
        })
    }

    fun sendChekingPresence(
        token: String,
        workerId: String,
        message: String,
    ) {
        try {
            getLoginUserCase.sendChekingPresence(token, workerId.toInt(), message)
                .enqueue(object : Callback<Boolean> {
                    override fun onResponse(call: Call<Boolean>, response: Response<Boolean>) {
                        if (!response.isSuccessful || response.message() == "false") {
                            _responseSalixMessage.value = ResponseItemVO(
                                isError = true,
                                errorMessage = getMessageFromAllResponse(
                                    nameofFunction(this), response.message()
                                )
                            )
                            //Log.i("Salix","Mensaje enviado a salix")
                        }

                    }

                    override fun onFailure(call: Call<Boolean>, t: Throwable) {
                        _responseSalixMessage.value = ResponseItemVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this), t.message!!
                            )
                        )

                    }
                })
        } catch (e: Exception) {
           //Log.d("error " + e.message)
        }

    }

    fun sectorCollection_get(usuario: String, password: String) {

        getPreSacadorUseCase.sectorCollection_get(usuario, password).enqueue(object :
            Callback<List<CollectionVO>> {
            override fun onFailure(call: Call<List<CollectionVO>>, t: Throwable) {
                val listError: ArrayList<CollectionVO> = ArrayList()
                listError.add(
                    CollectionVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                    )
                )
                _collectionList.value = CollectionListVO(listError)
            }


            override fun onResponse(
                call: Call<List<CollectionVO>>,
                response: Response<List<CollectionVO>>
            ) {
                if (response.body() != null) {
                    _collectionList.value =
                        response.body()?.let { CollectionListVO(it.toDateFormat(contextApp)) }
                } else {
                    val listError: ArrayList<CollectionVO> = ArrayList()
                    listError.add(
                        CollectionVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this),
                                response.message()
                            )
                        )
                    )
                    _collectionList.value = CollectionListVO(listError)

                }
            }

        })
    }

    fun sectorCollection_new(
        usuario: String,
        password: String,
        sectorFk: String
    ) {
        getPreSacadorUseCase.sectorCollection_new(usuario, password, sectorFk).enqueue(
            object :
                Callback<Unit> {
                override fun onFailure(call: Call<Unit>, t: Throwable) {
                    _responseNew.value =
                        ResponseItemVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this),
                                t.message!!
                            )
                        )


                }

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

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

                    }


                    //Log.i("Salix","Mensaje enviado a salix")


                    /*if (response.body() != null) {
                        _response.value =
                            ResponseItemVO(isError = false, response = response.body()!!)
                    } else {

                        _response.value = ResponseItemVO(
                            isError = true,
                            errorMessage =  getMessageFromAllResponse(nameofFunction(this),response.message())
                        )

                    }*/
                }
            })
    }

    fun sectorCollection_getSale(
        usuario: String,
        password: String,
        sectorCollectionFK: String,
        vSectorFk: String
    ) {
        getPreSacadorUseCase.sectorCollection_getSale(
            usuario,
            password,
            sectorCollectionFK,
            vSectorFk
        )
            .enqueue(object :
                Callback<List<PreSacadorItemVO>> {
                override fun onFailure(call: Call<List<PreSacadorItemVO>>, t: Throwable) {
                    _salesList.value = listOf()
                }

                override fun onResponse(
                    call: Call<List<PreSacadorItemVO>>,
                    response: Response<List<PreSacadorItemVO>>
                ) {
                    if (response.body() != null) {
                        _salesList.value = response.body()?.let { it }
                    } else {

                        _salesList.value = listOf()
                    }
                }
            })
    }

    fun sectorCollectionSaleGroup_add(
        usuario: String,
        password: String,
        vSaleGroupFk: String,
        vSectorCollectionFk: String
    ) {
        getPreSacadorUseCase.sectorCollectionSaleGroup_add(
            usuario,
            password,
            vSaleGroupFk,
            vSectorCollectionFk
        ).enqueue(
            object :
                Callback<Unit> {
                override fun onFailure(call: Call<Unit>, t: Throwable) {
                    _response.value =
                        ResponseItemVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this),
                                t.message!!
                            )
                        )


                }

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

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

                    }


                }
            })
    }

    fun saleTracking_addPrevOK(
        usuario: String,
        password: String,
        vSectorCollectionFk: String
    ) {
        getPreSacadorUseCase.saleTracking_addPrevOK(usuario, password, vSectorCollectionFk).enqueue(
            object :
                Callback<Unit> {
                override fun onFailure(call: Call<Unit>, t: Throwable) {
                    _responseSaleAddPrevOK.value =
                        ResponseItemVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this),
                                t.message!!
                            )
                        )


                }

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

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

                    }


                }
            })
    }

    fun saleTracking_updateIsChecked(
        usuario: String,
        password: String,
        vSaleFk: String,
        vIsChecked: String
    ) {
        getPreSacadorUseCase.saleTracking_updateIsChecked(usuario, password, vSaleFk, vIsChecked)
            .enqueue(
                object :
                    Callback<Unit> {
                    override fun onFailure(call: Call<Unit>, t: Throwable) {
                        _responseSaleupdateIsChecked.value =
                            ResponseItemVO(
                                isError = true,
                                errorMessage = getMessageFromAllResponse(
                                    nameofFunction(this),
                                    t.message!!
                                )
                            )


                    }

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

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

                        }


                    }
                })
    }


    fun itemShelving_updateFromSale(
        usuario: String,
        password: String,
        saleFk: String,
        visible: String
    ) {
        getSacadorControladorUserCase.itemShelving_updateFromSale(
            usuario,
            password,
            saleFk,
            visible
        )
            .enqueue(object : Callback<Unit> {
                override fun onFailure(call: Call<Unit>, t: Throwable) {
                    _responseItemShelvingUpdate.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                    )
                }

                override fun onResponse(call: Call<Unit>, response: Response<Unit>) {
                    if (!response.isSuccessful) {
                        _responseItemShelvingUpdate.value = ResponseItemVO(
                            isError = true,
                            errorMessage = getMessageFromAllResponse(
                                nameofFunction(this),
                                response.message()
                            )
                        )
                    } else {
                        _responseItemShelvingUpdate.value =
                            ResponseItemVO(isError = false, response = response.message()!!)
                    }
                }
            })
    }

    fun transferSalesSalix(
        token:String,
        ticketFk:String,
        saleFk: String,
        quantity: String,

        ) {
        getSacadorControladorUserCase.transferSalesSalix(
            token,
            ticketFk,
            saleFk,
            quantity

        ).enqueue(object : Callback<Any> {
            override fun onFailure(call: Call<Any>, t: Throwable) {
                _responseSplit.value = ResponseItemVO(
                    isError = true,
                    errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
                )
            }

            override fun onResponse(call: Call<Any>, response: Response<Any>) {
                //segio: salix devuelve id
                if (response.body() == null) {
                    _responseSplit.value = ResponseItemVO(
                        isError = true,
                        errorMessage = getMessageFromAllResponse(
                            nameofFunction(this),
                            response.message()
                        )
                    )
                } else {
                    _responseSplit.value =
                        ResponseItemVO(isError = false, response = response.message())
                }
            }
        })
    }


}
