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

import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.listener.OnActionResultListener;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.impl.ControlLightModelImpl;
import com.casic.dcms.mvp.presenter.IControlLightPresenter;
import com.casic.dcms.mvp.view.ILightControlView;

import java.util.List;

public class LightControlPresenterImpl extends BasePresenter implements IControlLightPresenter, OnActionResultListener {

    private final ILightControlView view;
    private final ControlLightModelImpl actionModel;

    public LightControlPresenterImpl(ILightControlView lightControlView) {
        this.view = lightControlView;
        actionModel = new ControlLightModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(List<Long> lampIds, String controlType) {
        view.showProgress();
        addSubscription(actionModel.sendControlLightRequest(lampIds, controlType));
    }

    @Override
    public void onSuccess(ActionResultBean resultBean) {
        view.hideProgress();
        view.obtainControlResult(resultBean);
    }

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

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