package com.xydl.cac.model.spectrogram;

import lombok.Data;

import java.io.DataInputStream;
import java.util.ArrayList;
import java.util.List;

@Data
public class SouthYsp extends SpectrogramModel {
    Float version;
    Float fileVersion;
    Short type;
    Long createTime;
    String flag;
    String name;
    Float xInterval;
    Float yMax;
    String xUnit;
    String yUnit;
    Integer k;
    Integer m;
    List<SouthYspChannel> channels = new ArrayList<>();

    public void readFrom(DataInputStream dis) throws Exception {
        version = readLittleEndianFloat(dis);
        fileVersion = readLittleEndianFloat(dis);
        type = readLittleEndianShort(dis);
        createTime = readLittleEndianLong(dis);
        flag = readString(dis, 1);
        name = readString(dis, 32);
        xInterval = readLittleEndianFloat(dis);
        yMax = readLittleEndianFloat(dis);
        xUnit = readString(dis, 1);
        yUnit = readString(dis, 1);
        k = readLittleEndianInt(dis);
        m = dis.read();
        for (int i = 0; i < m; i++) {
            SouthYspChannel channel = new SouthYspChannel();
            channel.readFrom(dis);
            channels.add(channel);
        }
        dis.readInt();
        for (SouthYspChannel channel : channels) {
            channel.readDataFrom(dis, k);
        }
    }
}
