package com.example.bpa.service;

import com.example.bpa.MainActivity;
import com.example.bpa.Model.IRun;
import com.example.bpa.Model.IRunT;
import com.example.bpa.Model.IThread;
import com.example.bpa.Model.IWriteCallBack;
import com.example.bpa.app.Main;
import com.example.bpa.config.ConfigName;
import com.example.bpa.helper.MessageLog;
import com.example.bpa.helper.ModbusTcpServer;
import com.example.bpa.helper.T;
import com.example.bpa.helper.ThreadManager;

/**
 * 扫码服务
 */
public class ScanCodeServer {

    //region 私有单例
    private static volatile ScanCodeServer _instance;

    public static ScanCodeServer Get() {
        if (_instance == null)
            _instance = new ScanCodeServer();
        return _instance;
    }

    private ScanCodeServer() {
    }
    //endregion

    //region 变量
    public String Code="";
    //endregion

    //region 公共函数
    /**
     * 初始化
     */
    public void Init()
    {
        //接收扫码信息
        DeviceData.Get().OnScanTheCodeInformationT=new IRunT<String>() {
            @Override
            public void Run(String s) {
                //1.查询订单信息
                //2.展示订单界面
                //3.制作订单信息
                //4.回馈订单信息
                Code=s;
                if (BusinessServer.Get().Commoditys.size() > 0) {
                    T.show(ConfigName.getInstance().dishesCon, "请等待前一饮品制作完成,在扫码！");
                    return;
                }else
                {
                    T.show(ConfigName.getInstance().dishesCon, "扫码成功："+Code+"，查询订单中请稍后!");
                    Main.getInstance().GetOrder(Code);
                    DeviceData.Get().setCodeClear(new IWriteCallBack() {
                        @Override
                        public void onSuccess() {
                        }
                        @Override
                        public void onFailure(String ErrorMsg) {
                        }
                    });
                }
            }
        };
    }

    /**
     * 业务流程
     */
    public void Business()
    {
        try
        {
            Code="0007a650-aaa5-4779-963e-b1ed0595514a";


        }catch (Exception ex)
        {
            MessageLog.ShowInfo("错误信息:"+ex.getMessage());
        }
    }
    //endregion
}
