package com.njzscloud.dispose.dev;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import com.njzscloud.common.mqtt.util.Mqtt;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public class WbsHandle {
    /**
     * 业务处理标识
     */
    public final String id;
    /**
     * 过磅系统编号
     */
    public final String sn;
    /**
     * 组号
     */
    public final String groupSn;
    /**
     * 道闸号
     */
    public final String barrierSn;

    /**
     * 播放语音
     *
     * @param content 语音内容
     * @param times   播放次数
     */
    public void playVoice(String content, int times) {
        if (times < 1) {
            times = 1;
        }
        Assert.notBlank(content, "语音内容不能为空");
        Mqtt.publish(sn + "/wbs/play_voice", MapUtil.builder()
            .put("id", id)
            .put("groupSn", groupSn)
            .put("barrierSn", barrierSn)
            .put("content", content)
            .put("times", times)
            .build());
    }

    /**
     * 播放语音（默认播放 1 次）
     *
     * @param content 语音内容
     */
    public void playVoice(String content) {
        playVoice(content, 1);
    }

    /**
     * 取过磅数据
     *
     * @param orderId 订单ID
     */
    public void obtainTruckData(Long orderId) {
        Mqtt.publish(sn + "/wbs/obtain_truck_data", MapUtil.builder()
            .put("id", id)
            .put("orderId", orderId.toString())
            .put("groupSn", groupSn)
            .put("barrierSn", barrierSn)
            .build());
    }

    /**
     * 打开道闸
     */
    public void open() {
        Mqtt.publish(sn + "/wbs/open", MapUtil.builder()
            .put("id", id)
            .put("groupSn", groupSn)
            .put("barrierSn", barrierSn)
            .build());
    }
}
