package de.tourenplaner.utils;

import de.tourenplaner.server.ErrorMessage;

import java.util.*;

/**
 * Use this class to generate easily a table with all ErrorMessages for AsciiDoc
 *
 * @author Christoph Haag, Sascha Meusel, Niklas Schnelle, Peter Vollmer
 */
public class ErrorMessagesToAsciiDoc {

    public static void main(String[] args) {

        HashMap<String, List<String>> table = new HashMap<String, List<String>>();
        
        for (ErrorMessage eMessage : ErrorMessage.values()) {
            if (!table.containsKey(eMessage.errorId) ) {
                table.put(eMessage.errorId, new ArrayList<String>());
                table.get(eMessage.errorId).add(eMessage.status.toString());
                table.get(eMessage.errorId).add(eMessage.message);
            }
            if (!"".equals(eMessage.details)) {
                table.get(eMessage.errorId).add(eMessage.details);
            }
        }

        String[] keyArray = table.keySet().toArray(new String[table.keySet().size()]);
        Arrays.sort(keyArray);

        //printing attributes
        for (String errorId : keyArray) {
            String errorIdLowerCase = errorId.toLowerCase();
            String idAttribute = errorIdLowerCase + "_id";
            String statusAttribute = errorIdLowerCase + "_status";
            String messageAttribute = errorIdLowerCase + "_message";
            String descriptionAttribute = errorIdLowerCase + "_description";
            
            System.out.println(":" + idAttribute + ": " + errorId);
            System.out.println(":" + statusAttribute + ": " + table.get(errorId).get(0));
            System.out.println(":" + messageAttribute + ": " + table.get(errorId).get(1));
            System.out.println(":" + descriptionAttribute + ": ");
            
            System.out.println(":" + errorIdLowerCase + ": " +
                    "<<{" + idAttribute + "},{" + idAttribute + "}>>" +
                    " - {" + statusAttribute + "}" +
                    " - {" + messageAttribute + "}");
            System.out.println();
        }


        System.out.println();
        System.out.println();
        System.out.println("== Errors");
        
        System.out.println("[options=\"header,autowidth\",cols=\"4*\"]");
        System.out.println("|==================================");
        System.out.println("|Error ID |Http Statuscode |Message and possible Details |Description");

        
        
        for (String errorId : keyArray) {

            String errorIdLowerCase = errorId.toLowerCase();
            String idAttribute = "{" + errorIdLowerCase + "_id}";
            String statusAttribute = "{" + errorIdLowerCase + "_status}";
            String messageAttribute = "{" + errorIdLowerCase + "_message}";
            String descriptionAttribute = "{" + errorIdLowerCase + "_description}";
            
            System.out.print("|" + idAttribute + "[[" + idAttribute+ "]] |" + statusAttribute + "|" + messageAttribute);

            for (int i=2; i < table.get(errorId).size(); i++) {
                System.out.println(" +");
                System.out.print("- " + table.get(errorId).get(i));
            }
            if (table.get(errorId).size() > 2) {
                System.out.println();
            } else {
                System.out.print(" ");
            }

            System.out.println("|" + descriptionAttribute);
            
        }


        System.out.println("|==================================");

    }

}

@@ -1372,85 +1372,8 @@
 e%22;%0A
-            String descriptionAttribute = errorIdLowerCase + %22_description%22;%0A
     
@@ -1634,75 +1634,8 @@
 ));%0A
-            System.out.println(%22:%22 + descriptionAttribute + %22: %22);%0A
     
@@ -2110,9 +2110,9 @@
 s=%5C%22
-4
+3
 *%5C%22%5D
@@ -2270,21 +2270,8 @@
 ails
- %7CDescription
 %22);%0A
@@ -2613,105 +2613,8 @@
 %7D%22;%0A
-            String descriptionAttribute = %22%7B%22 + errorIdLowerCase + %22_description%7D%22;%0A            %0A
     
@@ -3072,33 +3072,32 @@
 ;%0A            %7D%0A
-%0A
             Syst
@@ -3115,49 +3115,10 @@
 tln(
-%22%7C%22 + descriptionAttribute);%0A            
+);
 %0A   

Remove Description column, because it's useless