package com.sybotan.android.demo.viewmodel

import com.sybotan.android.demo.activities.BaseActivity
import com.sybotan.android.demo.bean.request.ReqEqToRel
import com.sybotan.android.demo.bean.request.ReqRelationEq
import com.sybotan.android.demo.bean.result.ResDeviceModel
import com.sybotan.android.demo.bean.result.ResEqRel
import com.sybotan.android.demo.entitiies.RelationEq
import com.sybotan.android.demo.retrofit.BaseObserver
import com.sybotan.android.demo.retrofit.BaseViewModelInterface
import com.sybotan.android.demo.retrofit.RetrofitFactory

class RelationVM(b: BaseViewModelInterface, a: BaseActivity) : BaseViewModel(b, a) {
    companion object {
        // 设备服务于空间
        const val EQ_SP_SERVE = "eq_sp_serve"

        // 设备 阀门 设备
        const val EQ_EQ_VV = "eq_eq_vv"

        // 设备 控制 设备
        const val EQ_EQ_CTRL = "EQ_EQ_CTRL"

        // 设备 电量 设备
        const val EQ_EQ_POWER = "EQ_EQ_POWER"

        // 设备 测量 设备
        const val EQ_EQ_SS = "EQ_EQ_SS"

        // 设备连接管道
        const val EQ_PIPE_CNCT = "EQ_PIPE_CNCT"
    }

    fun getEqs(spaceId: String) {
        val req = ReqRelationEq(spaceId)
        val observable = RetrofitFactory.getInstance().getRelationEqs(getRequestBody(req))
        sendRequest(observable, object : BaseObserver<List<RelationEq>>(mActivity, this) {
            override fun onSuccess(models: List<RelationEq>) {
                mEmitter.SendDircetive(EQ_SP_SERVE, models)
            }
        }, true)

    }

    fun addEq(rel: ReqEqToRel) {
        val observable = RetrofitFactory.getInstance().addEqToRel(getRequestBody(rel))
        this.sendRequest(observable, object : BaseObserver<ResEqRel>(mActivity, this) {
            override fun onSuccess(t: ResEqRel?) {
                mActivity.finish()
            }
        }, true)
    }

}