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.AlipayUserInfoRequestBean;
import com.hh.arome.bean.AlipayUserInfoResultBean;
import com.hh.arome.bean.SimpleResultBean;
import com.hh.arome.http.ApiService;
import com.hh.arome.http.HttpManager;
import com.hh.arome.mvp.contract.AlipayUserInfoContract;
import com.hh.arome.mvp.model.AlipayUserInfoModel;

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


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

    Context mContext;
    AlipayUserInfoModel mModel;
    AlipayUserInfoContract.View mView;


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


    @Override
    public void requestAlipayUserInfo(AlipayUserInfoRequestBean bean) {
        mModel.requestAlipayUserInfo(bean)
                .compose(RxHttpResponseCompat.<AlipayUserInfoResultBean>compatResult())
                .subscribe(new ProgressSubscriber<AlipayUserInfoResultBean>(mContext, mView, "获取三要素--- " + USER_INFO_THREE_ELEMENTS) {
                    @Override
                    public void onNext(AlipayUserInfoResultBean response) {
                        mView.showAlipayUserInfoResult(response);
                    }
                });
    }
}
