package com.hh.arome.mvp.presenter;

import android.app.Activity;
import android.content.Context;

import androidx.fragment.app.Fragment;

import com.common.lib_base.common.http.rx.RxHttpResponseCompat;
import com.common.lib_base.common.http.rx.subscriber.ProgressSubscriber;
import com.hh.arome.bean.DeviceConfigRequestBean;
import com.hh.arome.bean.DeviceConfigResultBean;
import com.hh.arome.bean.HeartBeatRequestBean;
import com.hh.arome.bean.SimpleResultBean;
import com.hh.arome.http.ApiService;
import com.hh.arome.http.HttpManager;
import com.hh.arome.mvp.contract.HeartbeatContract;
import com.hh.arome.mvp.model.DeviceConfigModel;
import com.hh.arome.mvp.model.HeartbeatModel;

import static com.hh.arome.common.Constants.Url.API_CONFIG_UPDATE;
import static com.hh.arome.common.Constants.Url.BASE_API_URL;
import static com.hh.arome.common.Constants.Url.BASE_URL;


/**
 * Date: 2022/8/3 0003 10:51
 * Description:
 */
public class HeartbeatPresenter implements HeartbeatContract.Presenter {

    Context mContext;
    HeartbeatModel mModel;
    HeartbeatContract.View mView;

    public HeartbeatPresenter(HeartbeatContract.View mView) {
        this.mView = mView;
        if (mView instanceof Fragment) {
            mContext = ((Fragment) mView).getActivity();
        } else {
            mContext = (Activity) mView;
        }
        this.mModel = new HeartbeatModel(HttpManager.getInstance(mContext.getApplicationContext()).create(ApiService.class));
    }


    @Override
    public void requestHeartbeat(HeartBeatRequestBean bean) {
        mModel.requestHeartBeat(bean)
                .compose(RxHttpResponseCompat.<SimpleResultBean>compatResult())
                .subscribe(new ProgressSubscriber<SimpleResultBean>(mContext, mView, "设备心跳 --- " + mModel.getUrlHeartbeatDefault()) {
                    @Override
                    public void onNext(SimpleResultBean response) {
                        mView.showHeartbeatResult(response);
                    }
                });
    }
}
