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.google.gson.Gson;
import com.hh.arome.bean.LogcatAddRequestBean;
import com.hh.arome.bean.SimpleResultBean;
import com.hh.arome.bean.ThreeElementsBean;
import com.hh.arome.http.ApiService;
import com.hh.arome.http.HttpManager;
import com.hh.arome.mvp.contract.DeviceConfigContract;
import com.hh.arome.mvp.contract.LogcatAddContract;
import com.hh.arome.mvp.contract.ThreeElementsContract;
import com.hh.arome.mvp.model.DeviceConfigModel;
import com.hh.arome.mvp.model.LogcatAddModel;
import com.hh.arome.mvp.model.ThreeElementsModel;

import java.util.Map;


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

    Context mContext;
    ThreeElementsModel mModel;
    ThreeElementsContract.View mView;
    public ThreeElementsPresenter(ThreeElementsContract.View mView) {
        this.mView = mView;
        if (mView instanceof Fragment) {
            mContext = ((Fragment) mView).getActivity();
        } else {
            mContext = (Activity) mView;
        }
        this.mModel = new ThreeElementsModel(HttpManager.getInstance(mContext.getApplicationContext()).create(ApiService.class));
    }
    @Override
    public void ThreeElementsContract(Map<String, Object> map, String url) {
        mModel.requestThreeElements(map,url)
                .compose(RxHttpResponseCompat.<ThreeElementsBean>compatResult())
                .subscribe(new ProgressSubscriber<ThreeElementsBean>(mContext, mView, "在线日志--- " + url) {
                    @Override
                    public void onNext(ThreeElementsBean response) {
                        mView.ThreeElementsContract(response);
                    }
                });
    }
}
