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

import com.casic.dcms.bean.MaintainRecordBean;
import com.casic.dcms.listener.OnGetMaintainRecordListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.MaintainRecordModelImpl;
import com.casic.dcms.mvp.presenter.IMaintainRecordPresenter;
import com.casic.dcms.mvp.view.IMaintainRecordView;

public class MaintainRecordPresenterImpl extends BasePresenter implements IMaintainRecordPresenter,
        OnGetMaintainRecordListener {

    private final IMaintainRecordView view;
    private final MaintainRecordModelImpl model;

    public MaintainRecordPresenterImpl(IMaintainRecordView cleanToiletRecordView) {
        this.view = cleanToiletRecordView;
        model = new MaintainRecordModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String startDate, String endDate, int offset) {
        view.showProgress();
        addSubscription(model.sendMaintainRecordRequest(startDate, endDate, offset));
    }

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

    @Override
    public void onSuccess(MaintainRecordBean result) {
        view.hideProgress();
        view.obtainRecordResult(result);
    }

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