package com.quyunshuo.module.home.utils;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;

import com.hboxs.serialport.sbc.thread.ThreadGlobalParam;
import com.quyunshuo.androidbaseframemvvm.common.util.LogUtil;
import com.quyunshuo.module.home.enums.DevStateEnum;

public class DevStataUtlis {
    /**
     * 设备开关机状态
     */
    public static void devOpenOrClose(String devCode, ThreadGlobalParam threadGlobalParam, MutableLiveData<Boolean> isShartup, MutableLiveData<Boolean> isfinash) {
        LogUtil.INSTANCE.e("backifo", "devCode:" + devCode);
        DevStateEnum devStateEnum = DevStateEnum.Companion.getEnumByValue(devCode);
        if (devStateEnum != null) {
            if (devStateEnum.getState() == 1 || devStateEnum.getState() == 2) {//点击开关机后，发送命令收到开机关机中回复，所以关闭继续发送开关机指令
                threadGlobalParam.stopSetM3();
            }
            if (devStateEnum.getState() == 1) {//展示开机中弹框
                isShartup.setValue(true);
            } else if (devStateEnum.getState() == 2) {//展示关机中弹框
                isShartup.setValue(false);
            }
            if (devStateEnum.getState() == 3 || devStateEnum.getState() == 0 || devStateEnum.getState() == -1) {////完成开关机
                isfinash.setValue(true);
            }
        }


    }

    /**
     * 处理致命错误和非致命弹框
     */
    public static void fatalErrorOrnonFatalError(String fatalError, String nonFatalError, MutableLiveData<String> data) {
        if (!"0000".equals(fatalError)) {
            data.setValue("01" + fatalError);
            //    threadGlobalParam.stopHeartbeat()
        } else if (!"0000".equals(nonFatalError)) {
            data.setValue("02" + nonFatalError);
            //  threadGlobalParam.stopHeartbeat()
        }

    }


    /**
     * 价值中弹框
     */
    public static void loadingDialog(String loadingCode, MutableLiveData<Boolean> data) {
        if (!"0000".equals(loadingCode)) {
            data.setValue(true);
        } else if ("0000".equals(loadingCode)) {
            data.setValue(false);

        }

    }

}
