package com.bbitcn.silk.ui.activity;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.bbitcn.silk.base.BasePresenter;
import com.bbitcn.silk.model.net.CommonResponse;
import com.bbitcn.silk.model.net.ToConvert;
import com.bbitcn.silk.utils.network.Url;
import com.bbitcn.silk.utils.network.XHttpManager;
import com.bbitcn.silk.utils.network.XHttpShorthand;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * @Author DuanKaiji
 * @CreateTime 2024年3月28日 10:06:01
 */
public class ConvertActivityPresenter extends BasePresenter {
    MutableLiveData<Integer> notice = new MutableLiveData<>();

    public ConvertActivityPresenter(@NonNull Application application) {
        super(application);
    }

    public MutableLiveData<Integer> getNotice() {
        return notice;
    }

    /**
     * 转换
     *
     * @param convert
     */
    public void convert(ToConvert convert) {
        showLoadingDialog("正在转换");
        RequestParams params = XHttpManager.getInstance().getRequestParams(Url.toConvert);
        params.addParameter("czsysid", convert.getCzsysid());
        params.addParameter("items", convert.getItems());
        x.http().post(params, new XHttpShorthand<CommonResponse>() {
            @Override
            public void success(CommonResponse model) {
                if (model.getResult()) {
                    successTips("转换成功");
                    notice.setValue(0);
                } else {
                    errorTips(model.getMsg());
                }
            }

            @Override
            public void error(Throwable e) {
                errorTips(e.getMessage());
            }

            @Override
            public void myFinish() {
                super.myFinish();
                hideLoadingDialog();
            }
        });

    }
}
