package com.xydl.cac.model.spectrogram;

import lombok.Data;

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

@Data
public class SouthPd extends SpectrogramModel {
    Float version;
    Float fileVersion;
    Short code;
    String flag;
    String name;
    String pdType;
    String warnLevel;
    String probabilityFlag;
    Float probability1;
    Float probability2;
    Float probability3;
    Float probability4;
    Float probability5;
    Float probability6;
    Float probability7;
    Integer m;
    Integer n;
    Integer p;
    Float hz50;
    Float hz100;
    String picType;
    String unit;
    Float minLimit;
    Float maxLimit;

    List<List<Integer>> dataPD;
    List<List<Float>> dataPS;

    public void readFrom(DataInputStream dis) throws Exception {
        version = readLittleEndianFloat(dis);
        fileVersion = readLittleEndianFloat(dis);
        code = readLittleEndianShort(dis);
        createTime = readLittleEndianLong(dis);
        flag = readString(dis, 1);
        name = readString(dis, 32);
        pdType = readString(dis, 1);
        warnLevel = readString(dis, 1);
        probabilityFlag = readString(dis, 1);
        probability1 = readLittleEndianFloat(dis);
        probability2 = readLittleEndianFloat(dis);
        probability3 = readLittleEndianFloat(dis);
        probability4 = readLittleEndianFloat(dis);
        probability5 = readLittleEndianFloat(dis);
        probability6 = readLittleEndianFloat(dis);
        probability7 = readLittleEndianFloat(dis);
        m = readLittleEndianInt(dis);
        n = readLittleEndianInt(dis);
        p = readLittleEndianInt(dis);
        hz50 = readLittleEndianFloat(dis);
        hz100 = readLittleEndianFloat(dis);
        picType = readString(dis, 1);
        unit = readString(dis, 1);
        minLimit = readLittleEndianFloat(dis);
        maxLimit = readLittleEndianFloat(dis);
        dis.readInt();

        if ("0".equalsIgnoreCase(picType)) {
            dataPD = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                List<Integer> list = new ArrayList<>();
                for (int j = 0; j < n; j++) {
                    Integer v = readLittleEndianInt(dis);
                    list.add(v);
                }
                dataPD.add(list);
            }
        } else if ("1".equalsIgnoreCase(picType)) {
            dataPS = new ArrayList<>();
            for (int i = 0; i < p; i++) {
                List<Float> list = new ArrayList<>();
                for (int j = 0; j < m; j++) {
                    Float v = readLittleEndianFloat(dis);
                    list.add(v);
                }
                dataPS.add(list);
            }
        }
    }
}
