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;

/**
 * 发动机数据 (0x04) —— GB/T 32960.3-2025。固定 5 字节。
 * 字段与 2016 版完全一致；保留独立类只为遵守"双版本不共用"原则。
 */
public final class EngineV2025BlockParser implements InfoBlockParser {

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

    @Override
    public InfoBlock parse(ByteBuffer buf) {
        Integer engineState = ValueDecoder.u8(buf);
        Integer crankshaftRpm = ValueDecoder.u16(buf);
        Double fuelRate = ValueDecoder.scaledU16(buf, 0.01);
        return new InfoBlock.Gb32960V2025.Engine(engineState, crankshaftRpm, fuelRate);
    }
}
