package openeye.notes.entries;

import java.io.File;

import openeye.notes.NoteCategory;
import openeye.notes.NoteLevels;
import openeye.notes.WrappedChatComponent;
import openeye.responses.ResponseModMsg;

import com.google.gson.JsonObject;

public class MsgNoteEntry extends NoteEntry {
	private final String description;
	private final String signature;
	private final String payload;

	public MsgNoteEntry(File file, ResponseModMsg msg) {
		super(file, calculateFromLevel(msg.level), msg.level);
		this.signature = msg.signature;
		this.description = msg.description;
		this.payload = msg.payload;
	}

	private static NoteCategory calculateFromLevel(int level) {
		if (level > NoteLevels.CRITICAL_LEVEL_THRESHOLD) return NoteCategory.CRITICAL;
		if (level > NoteLevels.ALERT_LEVEL_THRESHOLD) return NoteCategory.ALERT;
		else if (level > NoteLevels.WARNING_LEVEL_THRESHOLD) return NoteCategory.WARNING;
		else return NoteCategory.INFO;
	}

	@Override
	public String url() {
		return null; // TODO
	}

	@Override
	public WrappedChatComponent title() {
		return WrappedChatComponent.createTranslation("openeye.notes.title.note", file.getName());
	}

	@Override
	public WrappedChatComponent content() {
		return WrappedChatComponent.createTranslation(description);
	}

	@Override
	public JsonObject toJson() {
		JsonObject result = super.toJson();
		result.addProperty("signature", signature);
		result.addProperty("payload", payload);
		return result;
	}

}
@@ -200,16 +200,55 @@
 odMsg;%0A%0A
+import com.google.common.base.Strings;%0A
 import c
@@ -1273,26 +1273,39 @@
 .createT
-ranslation
+ext(Strings.nullToEmpty
 (descrip
@@ -1309,16 +1309,17 @@
 ription)
+)
 ;%0A%09%7D%0A%0A%09@
@@ -1505,8 +1505,9 @@
 t;%0A%09%7D%0A%0A%7D
+%0A

Derp No. 2