package com.sxyz.rfid.presenter.imp;

import android.app.Activity;

import androidx.fragment.app.Fragment;

import com.sxyz.rfid.presenter.IOutBoundPresenter;
import com.sxyz.rfid.presenter.model.OperatorBean;
import com.sxyz.rfid.presenter.model.OutBoundDetailModel;
import com.sxyz.rfid.presenter.model.OutboundFlowingWaterModel;
import com.sxyz.rfid.presenter.model.OutboundFridModel;
import com.sxyz.rfid.presenter.model.OutboundModel;
import com.sxyz.rfid.presenter.view.IOutBoundView;
import com.sxyz.rfid.retrofit.callback.Object1Observer;
import com.sxyz.rfid.retrofit.config.Transformer;
import com.sxyz.rfid.retrofit.http.RetrofitUtils;
import com.sxyz.rfid.widgets.CustomProgressDialog;

/**
 * @Description: 出库
 * @Project: rfid-app
 * @Package: com.sxyz.rfid.ui.out
 * @author: chunyuanwu
 * @date: 2025年12月29日 16:00:58
 * @version: 1.0.0
 */
public class OutBoundPresenterImpl implements IOutBoundPresenter {

    private IOutBoundView view;


    public OutBoundPresenterImpl(IOutBoundView view) {
        this.view = view;
    }

    @Override
    public void doOutBoundList(Fragment activity, int pageSize, int pageNum, String orderNo) {
        RetrofitUtils.getInstance().getApiService().getOutboundList(pageSize, pageNum, orderNo).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity.getActivity(), ""))).subscribe(new Object1Observer<OutboundModel>() {

            @Override
            public void onSuccess(OutboundModel model) {
                if (pageNum == 1) {
                    view.outBoundSuccess(model);
                } else {
                    view.outBoundLoadMoreSuccess(model);
                }
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doOutBoundDetailList(Activity activity, int orderId) {
        RetrofitUtils.getInstance().getApiService().getOutboundDetailList(10000000, 1, orderId).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity, ""))).subscribe(new Object1Observer<OutBoundDetailModel>() {

            @Override
            public void onSuccess(OutBoundDetailModel model) {
                view.outBoundDetailSuccess(model);
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doOutBoundFlowingWaterList(Activity activity, int itemId) {
        RetrofitUtils.getInstance().getApiService().getOutboundFlowList(10000000, 1, itemId).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity, ""))).subscribe(new Object1Observer<OutboundFlowingWaterModel>() {

            @Override
            public void onSuccess(OutboundFlowingWaterModel model) {
                view.outBoundFlowingWaterSuccess(model);
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doOutBoundCancel(Activity activity, int itemId) {
        RetrofitUtils.getInstance().getApiService().getCancelOutboundRelations(itemId, new OperatorBean(itemId)).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity, ""))).subscribe(new Object1Observer<Object>() {
            @Override
            public void onSuccess(Object model) {
                view.outBoundCancelSuccess();
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doOutBoundDetailCancel(Activity activity, int itemId) {
        RetrofitUtils.getInstance().getApiService().getCancelOutboundOrderCancelItem(itemId, new OperatorBean(itemId)).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity, ""))).subscribe(new Object1Observer<Object>() {
            @Override
            public void onSuccess(Object model) {
                view.outBoundDetailCancelSuccess();
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    /**
     * 查询出库流水-根据RFID标签查询
     *
     * @param activity
     * @param rfidTag
     */
    @Override
    public void doGetOutBoundFridList(Activity activity, String rfidTag) {
        RetrofitUtils.getInstance().getApiService().getOutboundFridList(rfidTag).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity, ""))).subscribe(new Object1Observer<OutboundFridModel>() {
            @Override
            public void onSuccess(OutboundFridModel model) {
                view.outBoundFridSuccess(model);
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doOutBoundFrid(Activity activity, OperatorBean dataBean) {
        RetrofitUtils.getInstance().getApiService().doOutBoundFrid(dataBean).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity, ""))).subscribe(new Object1Observer<Object>() {
            @Override
            public void onSuccess(Object model) {
                view.outSubmitBoundFridSuccess();
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }
}
