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 GLPageModel {
    private List<GLPageLineModel> lines;
    private PageFont font;

    public GLPageModel(List<GLPageLineModel> lines, PageFont font) {
        this.lines = lines;
        this.font = font;
    }

    public List<GLPageLineModel> getLines() {
        return lines;
    }

    public PageFont getFont() {
        return font;
    }

    public GLPageModel(JSONObject json) throws JSONException {
        this(
                jsonToLines(json.getJSONArray("lines")),
                PageFont.value(json.getString("font"))
        );
    }

    private static List<GLPageLineModel> jsonToLines(JSONArray array) throws JSONException {
        List<GLPageLineModel> lines = new ArrayList<GLPageLineModel>();
        for (int i = 0; i < array.length(); i++) {
            lines.add(new GLPageLineModel(array.getJSONObject(i)));
        }
        return lines;
    }


    public static enum PageFont {
        ARIAL("arial.ttf"),
        BOLD("bold.ttf"),
        TAHOMA("tahoma.ttf"),
        UBUNTUL("ubuntul.ttf"),
        AUTOBAHN("autobahn.ttf"),
        F25BANK("f25bank.ttf"),
        MONOTOON("monotoon.ttf"),
        UBUNTU("ubuntu.ttf"),
        VERDANA("verdana.ttf")
        ;
        String file;

        public String getFile() {
            return this.file;
        }

        PageFont(String filename){
            file = filename;
        }
        private static PageFont value(String font){
            for (PageFont type : values()) {
                if (type.name().equals(font)) {
                    return type;
                }
            }
            return null;
        }


    }


}
