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

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import es.verdnatura.domain.GetWokerMistakeUSerCase
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistake
import es.verdnatura.presentation.view.feature.workermistake.model.departmentMistakeList

import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

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

    private val getWorkerMistakeUserCase: GetWokerMistakeUSerCase = GetWokerMistakeUSerCase(context)

    private val _mistakeDepartmentList by lazy { MutableLiveData<departmentMistakeList>() }
    val mistakeDepartmentList: LiveData<departmentMistakeList>
        get() = _mistakeDepartmentList




  /*  fun mistakeWorker(usuario: String, password: String)
    {
        getWorkerMistakeUserCase.mistakeType(usuario, password)
            .enqueue(object : Callback<List<mistakeWorkerType>>
            {
                override fun onFailure(call: Call<List<mistakeWorkerType>>, t: Throwable)
                {
                    val listError: ArrayList<mistakeWorkerType> = ArrayList()
                    listError.add(mistakeWorkerType("0", ""))
                    _mistakeDepartmentList.value = workerMistakeTypeList(listError)
                }

                override fun onResponse(
                    call: Call<List<mistakeWorkerType>>,
                    response: Response<List<mistakeWorkerType>>
                )
                {
                    if (response.body() != null)
                    {
                        _mistakeDepartmentList.value = response.body()?.let { workerMistakeTypeList(it) }
                    } else
                    {
                        val listError: ArrayList<mistakeWorkerType> = ArrayList()
                        listError.add(mistakeWorkerType("0", ""))
                        _mistakeDepartmentList.value = workerMistakeTypeList(listError)
                    }
                }

            })
    }*/

    fun department_getHasMistake(usuario: String, password: String)
    {
        getWorkerMistakeUserCase.department_getHasMistake(usuario, password)
            .enqueue(object : Callback<List<DepartmentMistake>>
            {
                override fun onFailure(call: Call<List<DepartmentMistake>>, t: Throwable)
                {
                    val listError: ArrayList<DepartmentMistake> = ArrayList()
                    listError.add(DepartmentMistake("0", ""))
                    _mistakeDepartmentList.value = departmentMistakeList(listError)
                }

                override fun onResponse(
                    call: Call<List<DepartmentMistake>>,
                    response: Response<List<DepartmentMistake>>
                )
                {
                    if (response.body() != null)
                    {
                        _mistakeDepartmentList.value = response.body()?.let { departmentMistakeList(it) }
                    } else
                    {
                        val listError: ArrayList<DepartmentMistake> = ArrayList()
                        listError.add(DepartmentMistake("0", ""))
                        _mistakeDepartmentList.value = departmentMistakeList(listError)
                    }
                }

            })
    }



}
