package com.casic.dcms.mvp.presenter.impl;

import com.casic.dcms.bean.CleanRecordBean;
import com.casic.dcms.listener.OnGetCleanRecordListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.CleanRecordModelImpl;
import com.casic.dcms.mvp.presenter.ICleanRecordPresenter;
import com.casic.dcms.mvp.view.ICleanToiletRecordView;

public class CleanRecordPresenterImpl extends BasePresenter implements ICleanRecordPresenter, OnGetCleanRecordListener {

    private final ICleanToiletRecordView view;
    private final CleanRecordModelImpl model;

    public CleanRecordPresenterImpl(ICleanToiletRecordView cleanToiletRecordView) {
        this.view = cleanToiletRecordView;
        model = new CleanRecordModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String userId, String keywords, String beginDate, String endDate, int offset) {
        view.showProgress();
        addSubscription(model.sendCleanRecordRequest(userId, keywords, beginDate, endDate, offset));
    }

    @Override
    public void disposeRetrofitRequest() {
        unSubscription();
    }

    @Override
    public void onSuccess(CleanRecordBean result) {
        view.hideProgress();
        view.obtainCleanRecordResult(result);
    }

    @Override
    public void onFailure(Throwable throwable) {
        view.hideProgress();
    }
}
