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;

/**
 * 燃料电池发动机及车载氢系统数据 (0x03) —— GB/T 32960.3-2025 §7.2.4.5 表 17。固定 13 字节。
 */
public final class FuelCellV2025BlockParser implements InfoBlockParser {

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

    @Override
    public InfoBlock parse(ByteBuffer buf) {
        Double maxTempC = ValueDecoder.scaledU16WithOffset(buf, 0.1, -40.0);
        Integer maxTempProbeId = ValueDecoder.u8(buf);
        Double maxConcentration = ValueDecoder.scaledU16(buf, 0.000001);
        Integer maxConcentrationProbeId = ValueDecoder.u8(buf);
        Double maxPressure = ValueDecoder.scaledU16(buf, 0.1);
        Integer maxPressureProbeId = ValueDecoder.u8(buf);
        Integer hvDcDcStatus = ValueDecoder.u8(buf);
        Integer remainingH2Percent = ValueDecoder.u8(buf);
        Integer hvDcDcControllerTempC = ValueDecoder.tempOffset40(buf);
        return new InfoBlock.Gb32960V2025.FuelCell(
                maxTempC, maxTempProbeId,
                maxConcentration, maxConcentrationProbeId,
                maxPressure, maxPressureProbeId,
                hvDcDcStatus, remainingH2Percent, hvDcDcControllerTempC);
    }
}
