package cn.iododer.yudao.module.mqtt.enums;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 默认订阅的话题 -- 枚举类
 */
@Getter
@AllArgsConstructor
public enum DefineSubTopicEnum {

    //qos 0-至多1次、1-至少1次、2-正好一次
    ROBOT_STATUS("ROBOT_STATUS", 0,"点位"),
    ROBOT_TASK_STATUS("ROBOT_TASK_STATUS", 0,"机器人任务完成上报"),
    ROBOT_GENERICS_STATUS("ROBOT_GENERICS_STATUS", 0,"机器人异常"),
    SYNCHRONOUS_ALL_MAP_REQUEST("SYNCHRONOUS_ALL_MAP_REQUEST", 0,"路径规划需要初始数据上报"),
    TASK_ASSIGNMENT_FEEDBACK("TASK_ASSIGNMENT_FEEDBACK", 0,"路径规划任务分配上报"),
    TASK_ASSIGNMENT_FAIL("TASK_ASSIGNMENT_FAIL", 0,"路径规划失败上报");


    private final String topic;

    private final int qos;

    private final String msg;

    /**
     * 获取所有话题名
     *
     * @return topicArr
     */
    public static String[] queryAllTopic() {
        List<String> topicList = new ArrayList<>();
        for (DefineSubTopicEnum item : DefineSubTopicEnum.values()) {
            topicList.add(item.getTopic());
        }
        String[] topicArr = new String[topicList.size()];
        topicArr = topicList.toArray(topicArr);
        return topicArr;
    }


    /**
     * 获取所有qos
     *
     * @return qosArr
     */
    public static int[] queryAllQos() {
        List<Integer> qosList = new ArrayList<>();
        for (DefineSubTopicEnum item : DefineSubTopicEnum.values()) {
            qosList.add(item.getQos());
        }

        int[] qosArr = new int[qosList.size()];
        qosArr = qosList.stream().mapToInt(Integer::intValue).toArray();

        return qosArr;
    }

    public static DefineSubTopicEnum getDefineSubTopicEnumByTopic(String topic) {
        for (DefineSubTopicEnum item : DefineSubTopicEnum.values()) {
            if (item.getTopic().equals(topic)) {
                return item;
            }
        }
        return null;
    }

}