package com.youchain.utils;

import org.springframework.stereotype.Component;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * 滚筒任务路线
 * 下线：下线点 BYDGTO06、BYDGT007、BVDGTO01、BXDGT003、BYDGT005
 * 上线：上线点 BYDGTO02、BYDGTO04、BYDGTO08
 */
@Component
public class GtLineMap {
    /**
     * 关联关系映射
     */
    public static final Map<String, String> dataMap;

    /**
     * 上线点集合
     */
    private static final Set<String> ONLINE_POINTS;

    /**
     * 下线点集合
     */
    private static final Set<String> OFFLINE_POINTS;

    static {
        dataMap = new ConcurrentHashMap<>();
        // 初始化Map
        dataMap.put("BYDGT006", "BYDGT002");
        dataMap.put("BYDGT007", "BYDGT002");
        dataMap.put("BYDGT001", "BYDGT002");
        dataMap.put("BYDGT003", "BYDGT004");
        dataMap.put("BYDGT005", "BYDGT008");

        // 初始化上线点
        ONLINE_POINTS = new HashSet<>(Arrays.asList(
                "BYDGT002", "BYDGT004", "BYDGT008"
        ));

        // 初始化下线点
        OFFLINE_POINTS = new HashSet<>(Arrays.asList(
                "BYDGT001", "BYDGT003", "BYDGT005", "BYDGT006", "BYDGT007"
        ));

    }

    /**
     * 通过key获取value
     */
    public String getValueByKey(String key) {
        return dataMap.get(key);
    }

    /**
     * 通过value获取key
     */
    public String getKeyByValue(String value) {
        return dataMap.entrySet().stream()
                .filter(entry -> value.equals(entry.getValue()))
                .map(Map.Entry::getKey)
                .findFirst()
                .orElse(null);
    }

    /**
     * 判断是否为上线点
     */
    public boolean isOnlinePoint(String point) {
        return ONLINE_POINTS.contains(point);
    }

    /**
     * 判断是否为下线点
     */
    public boolean isOfflinePoint(String point) {
        return OFFLINE_POINTS.contains(point);
    }


}
