package com.lingniu.ingest.protocol.gb32960.codec.parser.vendor.guangdong;

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;

/**
 * 广东燃料电池规范 §7.2.3.6 表 17：DC/DC（燃料电池系统）数据。typeCode {@code 0x32}。
 *
 * <p>固定 9 字节：
 * <pre>
 *   inputVoltageV(2, 0.1V, 0~400V)
 *   inputCurrentA(2, 0.1A, 0~600A)
 *   outputVoltageV(2, 0.1V, 0~700V)
 *   outputCurrentA(2, 0.1A, 0~600A)
 *   controllerTempC(1, -40 offset)
 * </pre>
 *
 * <p>只有 vendor profile 命中 {@code guangdong-fc} 时才会解析到该结构；否则同一 typeCode 会落 Raw。
 */
public final class GdFcDcDcBlockParser implements InfoBlockParser {

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

    @Override
    public InfoBlock parse(ByteBuffer buf) {
        Double inV = ValueDecoder.scaledU16(buf, 0.1);
        Double inC = ValueDecoder.scaledU16(buf, 0.1);
        Double outV = ValueDecoder.scaledU16(buf, 0.1);
        Double outC = ValueDecoder.scaledU16(buf, 0.1);
        Integer ctrlTemp = ValueDecoder.tempOffset40(buf);
        return new InfoBlock.GuangdongFc.DcDc(inV, inC, outV, outC, ctrlTemp);
    }
}
