package seng302.Networking.MessageDecoders;

import seng302.Networking.Messages.AverageWind;
import seng302.Networking.Utils.ByteConverter;

import java.util.Arrays;

/**
 * Created by hba56 on 23/04/17.
 */
public class AverageWindDecoder {
    byte messageVersionNumber;
    byte[] byteTime;
    byte[] byteRawPeriod;
    byte[] byteRawSpeed;
    byte[] bytePeriod2;
    byte[] byteSpeed2;
    byte[] bytePeriod3;
    byte[] byteSpeed3;
    byte[] bytePeriod4;
    byte[] byteSpeed4;

    AverageWind averageWind;

    public AverageWindDecoder(byte[] encodedAverageWind) {
        messageVersionNumber = encodedAverageWind[0];
        byteTime = Arrays.copyOfRange(encodedAverageWind, 1, 7);
        byteRawPeriod = Arrays.copyOfRange(encodedAverageWind, 7, 9);
        byteRawSpeed = Arrays.copyOfRange(encodedAverageWind, 9, 11);
        bytePeriod2 = Arrays.copyOfRange(encodedAverageWind, 11, 13);
        byteSpeed2 = Arrays.copyOfRange(encodedAverageWind, 13, 15);
        bytePeriod3 = Arrays.copyOfRange(encodedAverageWind, 15, 17);
        byteSpeed3 = Arrays.copyOfRange(encodedAverageWind, 17, 19);
        bytePeriod4 = Arrays.copyOfRange(encodedAverageWind, 19, 21);
        byteSpeed4 = Arrays.copyOfRange(encodedAverageWind, 21, 23);

        int msgNum = ByteConverter.bytesToInt(messageVersionNumber);
        long lngTime = ByteConverter.bytesToLong(byteTime);
        int intRawPeriod = ByteConverter.bytesToInt(byteRawPeriod);
        int intRawSpeed = ByteConverter.bytesToInt(byteRawSpeed);
        int intPeriod2 = ByteConverter.bytesToInt(bytePeriod2);
        int intSpeed2 = ByteConverter.bytesToInt(byteSpeed2);
        int intPeriod3 = ByteConverter.bytesToInt(bytePeriod3);
        int intSpeed3 = ByteConverter.bytesToInt(byteSpeed3);
        int intPeriod4 = ByteConverter.bytesToInt(bytePeriod4);
        int intSpeed4 = ByteConverter.bytesToInt(byteSpeed4);

        this.averageWind = new AverageWind(msgNum, lngTime, intRawPeriod, intRawSpeed, intPeriod2, intSpeed2, intPeriod3, intSpeed3, intPeriod4, intSpeed4);

    }

    public AverageWind getAverageWind() {
        return averageWind;
    }
}
