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

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;

/**
 * 超级电容器极值数据 (0x32) —— GB/T 32960.3-2025 §7.2.4.11 表 26。固定 18 字节。
 */
public final class SuperCapacitorExtremeV2025BlockParser implements InfoBlockParser {

    @Override public ProtocolVersion version() { return ProtocolVersion.V2025; }
    @Override public int typeCode() { return 0x32; }
    @Override public int fixedLength() { return 18; }

    @Override
    public InfoBlock parse(ByteBuffer buf) {
        // 2025 超级电容极值的单体/探针编号为 2 字节，区别于 2016 蓄电池极值的 1 字节编号。
        Integer maxVSys = ValueDecoder.u8(buf);
        Integer maxVCell = ValueDecoder.u16(buf);
        Double maxV = ValueDecoder.scaledU16(buf, 0.001);
        Integer minVSys = ValueDecoder.u8(buf);
        Integer minVCell = ValueDecoder.u16(buf);
        Double minV = ValueDecoder.scaledU16(buf, 0.001);
        Integer maxTSys = ValueDecoder.u8(buf);
        Integer maxTProbe = ValueDecoder.u16(buf);
        Integer maxT = ValueDecoder.tempOffset40(buf);
        Integer minTSys = ValueDecoder.u8(buf);
        Integer minTProbe = ValueDecoder.u16(buf);
        Integer minT = ValueDecoder.tempOffset40(buf);
        return new InfoBlock.Gb32960V2025.SuperCapacitorExtreme(
                maxVSys, maxVCell, maxV,
                minVSys, minVCell, minV,
                maxTSys, maxTProbe, maxT,
                minTSys, minTProbe, minT);
    }
}
