package com.ruoyi.ss.model.domain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 型号标签
 * 2024/4/22
 */
@AllArgsConstructor
@Getter
public enum ModelTag {

    BLUETOOTH("1", "蓝牙"),
    WIFI("2", "WIFI"),
    FOUR_G("3", "4G"),
    GPS("4", "GPS"),
    ELE("5", "电量");

    private final String tag;
    private final String msg;

    public static ModelTag parse(String tag) {
        for (ModelTag obj : ModelTag.values()) {
            if (Objects.equals(obj.getTag(), tag)) {
                return obj;
            }
        }
        throw new RuntimeException("不存在值为" + tag + "的型号标签");
    }

    public static boolean contains(List<String> tags) {
        return new HashSet<>(Arrays.stream(ModelTag.values()).map(ModelTag::getTag).collect(Collectors.toList())).containsAll(tags);
    }

    // 判断列表中是否包含目标标签
    public static boolean hasAllTag(List<String> tags, ModelTag ...modelTags) {
        return new HashSet<>(Arrays.stream(modelTags).map(ModelTag::getTag).collect(Collectors.toList())).containsAll(tags);
    }

    public static boolean hasTag(List<String> modelTags, ModelTag modelTag) {
        return modelTags.contains(modelTag.getTag());
    }

    /**
     * 获取列表
     */
    public static List<String> asList(ModelTag ...tags) {
        return Arrays.stream(tags).map(ModelTag::getTag).collect(Collectors.toList());
    }

    /**
     * 判断是否为双模的型号功能
     */
    public static boolean isTwoMac(List<String> tags) {
        // 双模
        List<String> towMacTags = asList(FOUR_G, WIFI);
        return new HashSet<>(tags).containsAll(towMacTags);
    }
}
