package com.wdkl.ncs.android.middleware.logic.presenter.callingbed

import com.enation.javashop.net.engine.plugin.connection.ConnectionQuality
import com.enation.javashop.net.engine.plugin.exception.ExceptionHandle
import com.enation.javashop.net.engine.utils.ThreadFromUtils
import com.wdkl.ncs.android.lib.base.RxPresenter
import com.wdkl.ncs.android.lib.utils.ConnectionObserver
import com.wdkl.ncs.android.middleware.api.CallingbedApi
import com.wdkl.ncs.android.middleware.di.MiddlewareDaggerComponent
import com.wdkl.ncs.android.middleware.logic.contract.callingbed.InitActivityContract
import io.reactivex.disposables.Disposable
import javax.inject.Inject

class InitActivityPresenter @Inject constructor() : RxPresenter<InitActivityContract.View>(), InitActivityContract.Presenter {

    override fun bindDagger() {
        MiddlewareDaggerComponent.component.inject(this)
    }

    @Inject
    protected lateinit var initDeviceApi: CallingbedApi

    private val observer = object : ConnectionObserver<Any>() {
        override fun onStartWithConnection() {
            providerView().start()
        }

        override fun onNextWithConnection(result: Any, connectionQuality: ConnectionQuality) {
            providerView().complete("")
            providerView().setDeviceInfo()
        }

        override fun onErrorWithConnection(error: ExceptionHandle.ResponeThrowable, connectionQuality: ConnectionQuality) {
            providerView().onError(error.customMessage)
        }

        override fun attachSubscribe(var1: Disposable) {
            addDisposable(var1)
        }
    }

    override fun loadDeviceInfo(mac: String) {
        initDeviceApi.getDeviceInfo(mac)
                .map {
                    //
                }
                .compose(ThreadFromUtils.defaultSchedulers())
                .subscribe(observer)
    }
}