package com.fizz.business.constants.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

@Getter
@AllArgsConstructor
/**
 * 细粒度设备枚举（按你给出的17台设备）
 * position 为基准位置（单位：m），用于和 stripLocation 比较。
 * paramFields 列出该设备需要采样/缓存的字段名（与 AppMeasure*Message 中字段名对应）。
 */
public enum DeviceEnum {
    POR1(0, "1#开卷机", 0.0, Arrays.asList("tensionPorBr1", "stripSpeed")),
    POR2(1, "2#开卷机", 1.0, Arrays.asList("tensionPorBr2", "stripSpeed")),
    WELDER(2, "焊机", 5.0, Arrays.asList("weldStatus")),
    ENL1(3, "入口活套1", 10.0, Arrays.asList("celLength", "celCapacity", "tensionCel")),
    ENL2(4, "入口活套2", 12.0, Arrays.asList("celLength", "celCapacity", "tensionCel")),
    CLEAN(5, "清洗段", 20.0, Arrays.asList("cleaningVoltage", "cleaningCurrent", "alkaliConcentration", "alkaliTemperature")),
    FUR1(6, "退火炉-预热段", 30.0, Arrays.asList("phfExitStripTemp","potTemperature","gasConsumption")),
    FUR2(7, "退火炉-加热段", 40.0, Arrays.asList("rtfExitStripTemp","zincPotPower")),
    FUR3(8, "退火炉-冷却段", 50.0, Arrays.asList("jcsExitStripTemp","coolingTowerStripTemp")),
    FUR4(9, "退火炉-均衡段", 60.0, Arrays.asList("scsExitStripTemp")),
    TM(10, "光整机", 70.0, Arrays.asList("tensionBr5Tm", "stripSpeedTmExit")),
    TL(11, "拉矫机", 80.0, Arrays.asList("tlElongation", "tensionTlBr7")),
    COAT(12, "后处理段", 90.0, Arrays.asList(
            "avrCoatingWeightTop","stdCoatingWeightTop","maxCoatingWeightTop","minCoatingWeightTop",
            "avrCoatingWeightBottom","stdCoatingWeightBottom","maxCoatingWeightBottom","minCoatingWeightBottom",
            "airKnifePressure","airKnifeFlow","airKnifeGap","stripSpeedTmExit","tensionBr5Tm",
            "tensionTmBr6","tensionBr5Br6","tmMask","tmElongation","rollForceOperator","rollForceDrive",
            "motorTorque","bendingForce","antiCrimpingRollMesh","billyRollMesh",
            "tensionTlBr7","tensionBr6Br7","tlFlag","tlElongation","levelingUnit1Mesh","levelingUnit2Mesh",
            "antiCrossBowUnitMesh","tensionBr7Br8","stripSpeedAfp","stripTempAfp"
    )),
    CXL1(13, "出口活套1", 100.0, Arrays.asList("cxlLength", "cxlCapacity", "tensionCxl")),
    CXL2(14, "出口活套2", 102.0, Arrays.asList("cxlLength", "cxlCapacity", "tensionCxl")),
    INS(15, "检查站", 110.0, Arrays.asList("inspectionStatus")),
    TR(16, "卷取机", 120.0, Arrays.asList("coilLength", "speedExitSection", "tensionBr9Tr")),
    EXC(17, "卸卷小车", 999999.0, Collections.emptyList()),
    WEIGHT(18, "称重鞍座", 999999.0, Collections.emptyList());

    private final int idx;
    private final String desc;
    private final double basePosition;
    private final List<String> paramFields;

    private static final Map<String, DeviceEnum> NAME_MAP = new HashMap<>();
    static {
        for (DeviceEnum d : values()) NAME_MAP.put(d.name(), d);
    }
    public static DeviceEnum fromName(String name) { return NAME_MAP.get(name); }
}