package com.lingniu.ingest.protocol.gb32960.codec.parser.v2016;

import com.lingniu.ingest.protocol.gb32960.codec.InfoBlockParser;
import com.lingniu.ingest.protocol.gb32960.codec.ValueDecoder;
import com.lingniu.ingest.protocol.gb32960.model.InfoBlock;
import com.lingniu.ingest.protocol.gb32960.model.ProtocolVersion;

import java.nio.ByteBuffer;

/**
 * 动力蓄电池极值数据 (0x06) —— GB/T 32960.3-2016 表 B.16。固定 14 字节。
 * 2025 版 0x06 语义已变更为报警数据。
 */
public final class ExtremeValueV2016BlockParser implements InfoBlockParser {

    @Override public ProtocolVersion version() { return ProtocolVersion.V2016; }
    @Override public int typeCode() { return 0x06; }
    @Override public int fixedLength() { return 14; }

    @Override
    public InfoBlock parse(ByteBuffer buf) {
        // 极值块只给出子系统号/单体号/探针号及对应值，不包含完整单体数组。
        Integer maxVSub = ValueDecoder.u8(buf);
        Integer maxVCell = ValueDecoder.u8(buf);
        Double maxV = ValueDecoder.scaledU16(buf, 0.001);
        Integer minVSub = ValueDecoder.u8(buf);
        Integer minVCell = ValueDecoder.u8(buf);
        Double minV = ValueDecoder.scaledU16(buf, 0.001);
        Integer maxTSub = ValueDecoder.u8(buf);
        Integer maxTProbe = ValueDecoder.u8(buf);
        Integer maxT = ValueDecoder.tempOffset40(buf);
        Integer minTSub = ValueDecoder.u8(buf);
        Integer minTProbe = ValueDecoder.u8(buf);
        Integer minT = ValueDecoder.tempOffset40(buf);
        return new InfoBlock.Gb32960V2016.Extreme(
                maxVSub, maxVCell, maxV,
                minVSub, minVCell, minV,
                maxTSub, maxTProbe, maxT,
                minTSub, minTProbe, minT);
    }
}
