package com.neptune.plugin.models;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class GLPageLineModel {
    private List<GLPageUnitModel> units;
    private int top;

    public GLPageLineModel(List<GLPageUnitModel> units, int top) {
        this.units = units;
        this.top = top;
    }

    public GLPageLineModel(JSONObject json) throws JSONException {
        this(
                jsonToUnits(json.getJSONArray("units")),
                json.getInt("top"));
    }

    public List<GLPageUnitModel> getUnits() {
        return units;
    }

    public int getTop() {
        return top;
    }

    private static List<GLPageUnitModel> jsonToUnits(JSONArray array) throws JSONException {
        List<GLPageUnitModel> units = new ArrayList<GLPageUnitModel>();
        for (int i = 0; i < array.length(); i++) {
            units.add(new GLPageUnitModel(array.getJSONObject(i)));
        }
        return units;
    }



}
