package ca.firstvoices.rest.data;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({ "Dictionary", "Learn", "Resources", "About", "Kids" })
public class SiteMenu {

  public static final String MENU_ITEM_TITLE = "title";
  public static final String MENU_ITEM_ID = "id";
  public static final String MENU_ITEM_HREF = "href";
  public static final String MENU_ITEMS_DATA = "itemsData";
  public static final String MENU_TRANS_KEY = "transKey";


  @JsonProperty(value = "dictionary", required = true) public Map<String, Object> dictionaryTab =
      new LinkedHashMap<>();

  @JsonProperty(value = "learn", required = true) public Map<String, Object> learnTab =
      new LinkedHashMap<>();

  @JsonProperty(value = "resources", required = true) public Map<String, Object> resourcesTab =
      new LinkedHashMap<>();

  @JsonProperty(value = "about", required = true) public Map<String, Object>
      aboutTab = new LinkedHashMap<>();

  @JsonProperty(value = "kids", required = true) public Map<String, Object>
      kidsTab = new LinkedHashMap<>();

  public SiteMenu() {
    dictionaryTab.put(MENU_ITEM_TITLE, "Dictionary");
    dictionaryTab.put(MENU_ITEM_ID, "dictionary");
    dictionaryTab.put(MENU_ITEMS_DATA, setDefaultMenuItems("Dictionary"));
    dictionaryTab.put(MENU_TRANS_KEY, "general.dictionary");

    learnTab.put(MENU_ITEM_TITLE, "Learn");
    learnTab.put(MENU_ITEM_ID, "learn");
    learnTab.put(MENU_ITEMS_DATA, setDefaultMenuItems("Learn"));
    learnTab.put(MENU_TRANS_KEY, "general.learn");

    resourcesTab.put(MENU_ITEM_TITLE, "Resources");
    resourcesTab.put(MENU_ITEM_ID, "resources");
    resourcesTab.put(MENU_ITEMS_DATA, setDefaultMenuItems("Resources"));
    resourcesTab.put(MENU_TRANS_KEY, "general.resources");

    aboutTab.put(MENU_ITEM_TITLE, "About");
    aboutTab.put(MENU_ITEM_ID, "about");
    aboutTab.put(MENU_ITEMS_DATA, setDefaultMenuItems("About"));
    aboutTab.put(MENU_TRANS_KEY, "general.about");

    kidsTab.put(MENU_ITEM_TITLE, "Kids");
    kidsTab.put(MENU_ITEM_ID, "kids");
    kidsTab.put(MENU_ITEM_HREF, "/kids");
    kidsTab.put(MENU_ITEMS_DATA, setDefaultMenuItems("Kids"));
    kidsTab.put(MENU_TRANS_KEY, "general.kids");
  }

  private LinkedList<Map<String, String>> setDefaultMenuItems(String tab) {
    HashMap<String, String> pages = new LinkedHashMap<>();
    HashMap<String, String> translations = new HashMap<>();

    switch (tab) {
      case "Dictionary":
        pages.put("/words", "Words");
        pages.put("/phrases", "Phrases");
        pages.put("/alphabet", "Alphabet");
        pages.put("/categories", "Categories");

        translations.put("Words", "general.words");
        translations.put("Phrases", "general.phrases");
        translations.put("Alphabet", "general.alphabet");
        translations.put("Categories", "general.categories");
        break;

      case "Learn":
        pages.put("/songs", "Songs");
        pages.put("/stories", "Stories");
        pages.put("/games", "Games");

        translations.put("Songs", "general.songs");
        translations.put("Stories", "general.stories");
        translations.put("Games", "general.games");
        break;

      case "Resources":
        pages.put("/apps", "Mobile App");
        pages.put("/keyboards", "Keyboards");

        translations.put("Apps", "general.apps");
        translations.put("Keyboards", "general.keyboards");
        break;

      case "About":
        pages.put("/our-language", "Our Language");
        pages.put("/our-people", "Our People");

        translations.put("Our Language", "general.our_language");
        translations.put("Our People", "general.our_people");
        break;

      default:
        return new LinkedList<>();
    }

    return formatMenuItems(pages, translations);
  }

  private LinkedList<Map<String, String>> formatMenuItems(HashMap<String, String> pages, HashMap<String, String> translations) {
    LinkedList<Map<String, String>> dictionaryMenuItems = new LinkedList<>();

    pages.forEach((key, value) -> {
      String translation = translations.get(value);

      HashMap<String, String> formattedPage = new HashMap<>();
      formattedPage.put(MENU_ITEM_TITLE, value);
      formattedPage.put("href", key);
      formattedPage.put(MENU_TRANS_KEY, translation == null ? "" : translation);

      dictionaryMenuItems.add(formattedPage);
    });

    return dictionaryMenuItems;
  }
}
@@ -737,17 +737,16 @@
 sKey%22;%0A%0A
-%0A
   @JsonP
@@ -783,32 +783,34 @@
 required = true)
+%0A 
  public Map%3CStri
@@ -832,30 +832,24 @@
 tionaryTab =
-%0A     
  new LinkedH
@@ -902,32 +902,34 @@
 required = true)
+%0A 
  public Map%3CStri
@@ -946,30 +946,24 @@
 %3E learnTab =
-%0A     
  new LinkedH
@@ -1020,32 +1020,34 @@
 required = true)
+%0A 
  public Map%3CStri
@@ -1072,22 +1072,16 @@
 cesTab =
-%0A     
  new Lin
@@ -1138,32 +1138,34 @@
 required = true)
+%0A 
  public Map%3CStri
@@ -1175,22 +1175,16 @@
  Object%3E
-%0A     
  aboutTa
@@ -1259,16 +1259,18 @@
  = true)
+%0A 
  public 
@@ -1288,22 +1288,16 @@
  Object%3E
-%0A     
  kidsTab
@@ -3493,18 +3493,12 @@
 %22, %22
-Mobile 
 App
+s
 %22);%0A
@@ -4134,16 +4134,22 @@
 %3E pages,
+%0A     
  HashMap
@@ -4673,8 +4673,9 @@
 s;%0A  %7D%0A%7D
+%0A

Fix missing transKey from Resources menu