package com.cooleshow.teacher.presenter.income;

import com.cooleshow.base.constanst.Constants;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.rx.BaseObserver;
import com.cooleshow.base.utils.RequestBodyUtil;
import com.cooleshow.teacher.api.APIService;
import com.cooleshow.teacher.bean.WithdrawalRecordBean;
import com.cooleshow.teacher.contract.WithdrawalRecordContract;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 创建日期：2022/5/24 10:14
 *
 * @author Ryan
 * 类说明：
 */
public class WithdrawalRecordPresenter extends BasePresenter<WithdrawalRecordContract.WithdrawalRecordView> implements WithdrawalRecordContract.Presenter {
    public void getWithdrawalPage(boolean isLoading,int page,String searchDate,String status){
        if (isLoading && getView() != null) {
            getView().showLoading();
        }
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("searchDate",searchDate);
            //状态 DOING、审核中 PASS、通过 UNPASS、不通过
            jsonObject.put("status",status);
            jsonObject.putOpt("page", page);
            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addSubscribe(create(APIService.class).getWithdrawalPage(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<WithdrawalRecordBean>(getView()) {
            @Override
            protected void onSuccess(WithdrawalRecordBean data) {
                if (getView() != null) {
                    getView().withdrawalPageSuccess(page, data);
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                getView().hideLoading();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if (getView() != null) {
                    getView().withdrawalPageError(page);
                }
            }
        });
    }
}
