package org.fullmetalfalcons.scouting.main;

import com.dd.plist.NSDictionary;
import org.fullmetalfalcons.scouting.elements.Element;
import org.fullmetalfalcons.scouting.exceptions.ElementParseException;
import org.fullmetalfalcons.scouting.fileio.Reader;
import org.fullmetalfalcons.scouting.fileio.Writer;
import org.fullmetalfalcons.scouting.teams.Team;

import javax.swing.*;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Main class
 *
 * Created by Dan on 1/11/2016.
 */
public class Main {

    private static final ArrayList<Element> ELEMENTS = new ArrayList<>();
    private static final ArrayList<Team> TEAMS = new ArrayList<>();
    //Console spam
    private static boolean debug = false;

    public static void main(String args[]){
        try {
            log("Program Starting");
            log("Starting to load configuration");
            Reader.loadConfig();
            log(ELEMENTS.size() + " elements loaded");
            log("Starting to load plists");
            Reader.loadPlists();
            log(TEAMS.size() + " teams loaded");
            log("Starting to write file");
            Writer.write();
            log("Results saved to " + Writer.FILENAME);
            log("Exiting program");
            System.exit(0);
        } catch(Exception e){
            sendError("Unknown error occurred: " + e.toString());
            System.exit(-1);
        }


    }

    public static void addElement(String line){

        try {
            Element e = new Element(line);
            debug("Element of type " + e.getType().toString() + " created");
            ELEMENTS.add(e);
        } catch (ElementParseException e) {
            sendError("Config error: " + e.getMessage());
        }
    }

    public static void addTeam(NSDictionary dictionary){
        Team t = new Team(dictionary);
        debug("Team " + t.getValue(Team.NUMBER_KEY) + " loaded");
        TEAMS.add(t);
    }

    public static ArrayList<Element> getElements(){
        return ELEMENTS;
    }

    public static ArrayList<Team> getTeams() {
        return TEAMS;
    }

    public static void sendError(String message){
        try {
            JOptionPane.showMessageDialog(null, message,
                    "You done messed up", JOptionPane.ERROR_MESSAGE);
        } catch (Exception e){
            JOptionPane.showMessageDialog(null, "An error occurred while displaying an error",
                    "Yo Dawg!", JOptionPane.ERROR_MESSAGE);
        }
    }

    public static void debug(String message){
        if (debug){
            System.out.println(message);
        }
    }

    public static void log(String message){
        System.out.println(message);
    }
}

@@ -378,36 +378,8 @@
 .*;%0A
-import java.io.IOException;%0A
 impo
@@ -665,16 +665,22 @@
 tic 
+final 
 boolean 
 debu
@@ -679,20 +679,19 @@
 ean 
-debug = fals
+DEBUG = tru
 e;%0A%0A
@@ -2059,32 +2059,160 @@
 n TEAMS;%0A    %7D%0A%0A
+    /**%0A     * Sends an error message to the user with a JOptionPane%0A     *%0A     * @param message error message to send%0A     */%0A
     public stati
@@ -2647,21 +2647,21 @@
     if (
-debug
+DEBUG
 )%7B%0A     

Add comments and debug and more formatting