package com.sxyz.rfid.presenter.imp;

import android.app.Activity;

import androidx.fragment.app.Fragment;

import com.sxyz.rfid.presenter.IReviewPresenter;
import com.sxyz.rfid.presenter.model.ReviewDetailListModel;
import com.sxyz.rfid.presenter.model.ReviewDetailModel;
import com.sxyz.rfid.presenter.model.ReviewModel;
import com.sxyz.rfid.presenter.model.ReviewResultModel;
import com.sxyz.rfid.presenter.model.ReviewRfidTaskCheckModel;
import com.sxyz.rfid.presenter.model.ReviewTaskCheck;
import com.sxyz.rfid.presenter.view.IReviewView;
import com.sxyz.rfid.retrofit.callback.Object1Observer;
import com.sxyz.rfid.retrofit.callback.Object2Observer;
import com.sxyz.rfid.retrofit.callback.ObjectObserver;
import com.sxyz.rfid.retrofit.config.Transformer;
import com.sxyz.rfid.retrofit.http.RetrofitUtils;
import com.sxyz.rfid.utils.ToastUtil;
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 ReviewPresenterImpl implements IReviewPresenter {

    private IReviewView view;


    public ReviewPresenterImpl(IReviewView view) {
        this.view = view;
    }

    @Override
    public void doReviewList(Fragment activity, int pageSize, int pageNum, String taskNo) {
        RetrofitUtils.getInstance().getApiService().getReviewList(pageSize, pageNum, taskNo).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity.getActivity(), ""))).subscribe(new Object1Observer<ReviewModel>() {

            @Override
            public void onSuccess(ReviewModel model) {
                if (pageNum == 1) {
                    view.reviewSuccess(model);
                } else {
                    view.reviewLoadMoreSuccess(model);
                }
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doDeleteReviewTask(Fragment activity, int taskId) {
        RetrofitUtils.getInstance().getApiService().deleteReviewTask(taskId).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity.getActivity(), ""))).subscribe(new Object1Observer<Object>() {

            @Override
            public void onSuccess(Object model) {
                view.deleteReviewTaskSuccess();
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doReviewDetail(Activity activity, int taskId) {
        RetrofitUtils.getInstance().getApiService().getReviewDetail(taskId).compose(Transformer.switchSchedulers()).subscribe(new Object1Observer<ReviewDetailModel>() {

            @Override
            public void onSuccess(ReviewDetailModel model) {
                view.reviewDetailSuccess(model);
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doReviewDetailList(Activity activity, int taskId) {
        RetrofitUtils.getInstance().getApiService().getReviewDetailList(10000000, 1, taskId).compose(Transformer.switchSchedulers()).subscribe(new Object1Observer<ReviewDetailListModel>() {

            @Override
            public void onSuccess(ReviewDetailListModel model) {
                view.reviewDetailListSuccess(model);
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doReviewResult(Activity activity, int taskId) {
        RetrofitUtils.getInstance().getApiService().getReviewResult(taskId).compose(Transformer.switchSchedulers()).subscribe(new Object1Observer<ReviewResultModel>() {

            @Override
            public void onSuccess(ReviewResultModel model) {
                view.reviewResultSuccess(model);
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doReviewScanTaskCheck(Activity activity, ReviewTaskCheck reviewTaskCheck) {
        RetrofitUtils.getInstance().getApiService().doReviewScanTaskCheck(reviewTaskCheck).compose(Transformer.switchSchedulers()).subscribe(new Object1Observer<ReviewRfidTaskCheckModel>() {

            @Override
            public void onSuccess(ReviewRfidTaskCheckModel model) {
                view.reviewScanTaskCheckSuccess(model);
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }

    @Override
    public void doReviewRfidTaskCheck(Activity activity, ReviewTaskCheck reviewTaskCheck) {
        RetrofitUtils.getInstance().getApiService().doReviewRfidTaskCheck(reviewTaskCheck).compose(Transformer.switchSchedulers()).subscribe(new Object1Observer<ReviewRfidTaskCheckModel>() {

            @Override
            public void onSuccess(ReviewRfidTaskCheckModel model) {
                view.reviewRfidTaskCheckSuccess(model);
            }

            @Override
            public void onFailed(Throwable throwable) {
            }
        });

    }

    @Override
    public void doStopReviewTask(Fragment activity, int taskId) {
        RetrofitUtils.getInstance().getApiService().doStopReviewTask(taskId).compose(Transformer.switchSchedulers(CustomProgressDialog.createLoadingDialog(activity.getActivity(), ""))).subscribe(new Object1Observer<Object>() {

            @Override
            public void onSuccess(Object model) {
                view.stopReviewTaskSuccess();
            }

            @Override
            public void onFailed(Throwable throwable) {

            }
        });
    }
}
