package com.persagy.functions.weather.constant;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class Const {
	public static final String LOCATION = "LOCATION";
	public static final String DAYSTART = "DAYSTART";
	public static final String DAYEND = "DAYEND";
	private static final String persagyKey = "VV8BHVPBY8";
	private static final String persagyKey2 = "S-hcBcOfI-tj-gvwh";
	private static final String sagaKey = "ebaahic4gjtb17fk";
	
	public static class AboutTime {
		/** 1 * 60 * 1000L */
		public static final long minMinlliseconds = 1 * 60 * 1000L;
		/** 5 * 60 * 1000L */
		public static final long min5Minlliseconds = 5 * minMinlliseconds;
		/** 15 * 60 * 1000L */
		public static final long min15Minlliseconds = 15 * minMinlliseconds;
		/** 30 * 60 * 1000L */
		public static final long min30Minlliseconds = 30 * minMinlliseconds;
		/** 60 * 60 * 1000L */
		public static final long hourMilliseconds = 60 * minMinlliseconds;
	}
	
	public enum API {
		nowWeather, nowAir, dayPredict, alarm, hour24Predict, hour24History
	}
	
	public static final List<String> iconTheme = new ArrayList<>(Arrays.asList("light","dark","classic"));
	public static final TreeMap<String, String> iconSize = new TreeMap<>();
	static {
		iconSize.put("small", "1");
		iconSize.put("big", "2");
	}
	
	public static class ServiceURL {
		public static String nowWeather = "https://api.seniverse.com/v3/weather/now.json?key="+persagyKey+"&language=zh-Hans&unit=c&location=LOCATION";
		public static String nowAir = "https://api.seniverse.com/v3/air/now.json?key="+persagyKey+"&language=zh-Hans&scope=city&location=LOCATION";
		public static String dayPredict = "https://api.seniverse.com/v3/weather/daily.json?key="+persagyKey+"&language=zh-Hans&unit=c&start=DAYSTART&days=DAYEND&location=LOCATION";
		public static String alarm = "https://api.seniverse.com/v3/weather/alarm.json?key="+persagyKey2;
		public static String hour24Predict = "https://api.seniverse.com/v3/weather/hourly.json?key="+sagaKey+"&language=zh-Hans&unit=c&start=0&hours=24&location=LOCATION";
		public static String hour24History = "https://api.seniverse.com/v3/weather/hourly_history.json?key="+persagyKey2+"&language=zh-Hans&unit=c&location=LOCATION";
	}
	
	private static Map<String, Integer> requestStatic = new HashMap<>();
	public static void requestAdd(API api) {
		synchronized (requestStatic) {
			Integer num = requestStatic.get(api.name());
			if(num == null) {
				requestStatic.put(api.name(), 1);
			}else {
				requestStatic.put(api.name(), num + 1);
			}
		}
	}
	public static Map<String, Integer> popAll() {
		Map<String, Integer> result = new HashMap<>();
		synchronized (requestStatic) {
			result.putAll(requestStatic);
			requestStatic.clear();
		}
		return result;
	}
	
	public static class ErrorTag {
		public static String paramMis = "necessary parameters missing";
		public static String paramFormat = "parameter format error";
		public static String paramUnrecognized = "unrecognized parameter value";
		public static String paramValueError = "parameter value error";
		public static String timeToLong = "time span is too long";
		public static String timeEndBeforeStart = "timeStart > timeEnd";
		public static String timeSpanLack = "timeStart or timeEnd is unidentified";
		public static String cityNotFound = "can not find the right city";
		public static String cityUnsupport = "city unsupported";
		public static String service3rd = "3rd service error";
		public static String service = "dao service error";
	}
}
