package com.example.fitbot.processing;

public class MotionData {

    // Data of the motion sensor
    public float accelerationX;
    public float accelerationY;
    public float accelerationZ;
    public float rotationX;
    public float rotationY;
    public float rotationZ;

    // Delimiter for the data received from the motion sensor
    private static final String DATA_DELIMITER = ";";

    /**
     * Constructor for the MotionData class.
     *
     * @param accelerationX The acceleration in the X axis in m/s^2.
     * @param accelerationY The acceleration in the Y axis in m/s^2.
     * @param accelerationZ The acceleration in the Z axis in m/s^2.
     * @param rotationX     The rotation in the X axis in degrees.
     * @param rotationY     The rotation in the Y axis in degrees.
     * @param rotationZ     The rotation in the Z axis in degrees.
     */
    public MotionData(float accelerationX, float accelerationY, float accelerationZ, float rotationX, float rotationY, float rotationZ) {
        this.accelerationX = accelerationX;
        this.accelerationY = accelerationY;
        this.accelerationZ = accelerationZ;
        this.rotationX = rotationX;
        this.rotationY = rotationY;
        this.rotationZ = rotationZ;
    }

    /**
     * Function for decoding a string into a MotionData object.
     * This string must contain the data of the motion sensor
     * separated by the delimiter. (;)
     *
     * @param data The string containing the data of the motion sensor.
     * @return An instance of MotionData.
     */
    public static MotionData decode(String data) {
        String[] parts = data.split(DATA_DELIMITER);
        return new MotionData(
                Float.parseFloat(parts[0]),
                Float.parseFloat(parts[1]),
                Float.parseFloat(parts[2]),
                Float.parseFloat(parts[3]),
                Float.parseFloat(parts[4]),
                Float.parseFloat(parts[5])
        );
    }

}
