package com.sybotan.android.demo.viewmodel

import com.sybotan.android.demo.activities.BaseActivity
import com.sybotan.android.demo.bean.request.ReqDeviceJob
import com.sybotan.android.demo.bean.result.ResDeviceModel
import com.sybotan.android.demo.entitiies.DeviceType
import com.sybotan.android.demo.retrofit.BaseObserver
import com.sybotan.android.demo.retrofit.BaseViewModelInterface
import com.sybotan.android.demo.retrofit.RetrofitFactory

class DeviceVM(b: BaseViewModelInterface, a: BaseActivity) : BaseViewModel(b, a) {
    companion object {
        const val DEVICE_TYPE = "DEVICE_TYPE"
        const val DEVICE_ADD = "DEVICE_ADD"

    }

    fun getDeviceType() {
        val observable = RetrofitFactory.getInstance().requestDeviceTypeJob()
        this.sendRequest(
            observable,
            object : BaseObserver<List<DeviceType>>(mActivity, this) {
                override fun onSuccess(t: List<DeviceType>?) {
                    mEmitter.SendDircetive(DEVICE_TYPE, t)
                }
            }, true
        )
    }


    fun addDevice(device: ReqDeviceJob) {
        val observable = RetrofitFactory.getInstance().addDeviceJob(getRequestBody(device))
        this.sendRequest(
            observable,
            object : BaseObserver<ResDeviceModel>(mActivity, this) {
                override fun onSuccess(t: ResDeviceModel?) {
                    mEmitter.SendDircetive(DEVICE_ADD, t)
                }

            },
            true
        )
    }
}