package org.fouram.core.util;

import java.util.Date;

import com.fasterxml.jackson.databind.JsonNode;

public class JsonNodeUtil {

	public static String getValue(JsonNode userNode, String key) {
		String value = userNode.get(key).asText().trim();
		if (Tools.isEmpty(value)) {
			return "";
		}
		if (value.contains("/Date(")) {
			Date date = new Date(Long.valueOf(value.replace("/Date(", "").replace(")/", "").replace("+0000", "")));
			return DateUtil.getDay(date);
		}
		return value;
	}
	
	public static String getTime(JsonNode userNode, String key) {
		String value = userNode.get(key).asText().trim();
		if (Tools.isEmpty(value)) {
			return "";
		}
		if (value.contains("/Date(")) {
			Date date = new Date(Long.valueOf(value.replace("/Date(", "").replace(")/", "").replace("+0000", "")));
			return DateUtil.getTime(date);
		}
		return value;
	}

	public static String getValue(JsonNode userNode, String key1, String key2) {
		String value = null;
		if (userNode.get(key1) != null && userNode.get(key1).get(key2) != null) {
			value = userNode.get(key1).get(key2).asText().trim();
		}
		if (Tools.isEmpty(value)) {
			return "";
		}
		return value;
	}

	public static void main(String[] args) {
		System.out.println(DateUtil.getDay(new Date(1577923200000L)));
	}
}