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.SubmitShopCaseModelImpl;
import com.casic.dcms.mvp.presenter.ISubmitShopCasePresenter;
import com.casic.dcms.mvp.view.ICaseSubmitView;

/**
 * @Author: Pengxh
 * @Time: 2021/4/12 13:29
 * @Email: 290677893@qq.com
 **/
public class ShopCaseSubmitPresenterImpl extends BasePresenter implements ISubmitShopCasePresenter,
        OnActionResultListener {

    private final ICaseSubmitView view;
    private final SubmitShopCaseModelImpl actionModel;

    public ShopCaseSubmitPresenterImpl(ICaseSubmitView submitCaseView) {
        this.view = submitCaseView;
        actionModel = new SubmitShopCaseModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(String isNeedVerify, String isNeedRevisit, String longitude, String latitude,
                                       String source, String caseLevel, String areaCode, String streetCode,
                                       String communityCode, String gridId, String description, String fieldintro,
                                       String fileIdVerify, int bzhours, int bzminis, String shopId,
                                       String shopkeeperName, String shopPhone) {
        view.showProgress();
        addSubscription(actionModel.sendShopCaseSubmitRequest(isNeedVerify, isNeedRevisit, longitude, latitude,
                source, caseLevel, areaCode, streetCode, communityCode, gridId, description, fieldintro, fileIdVerify,
                bzhours, bzminis, shopId, shopkeeperName, shopPhone));
    }

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

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

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