package com.javahonk.controller;

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

import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BodyOnLoadController {

	@RequestMapping(value = "/helloWorld.web", method = RequestMethod.GET)
	public String printWelcome(ModelMap model) {

		return "index";
	}

	@RequestMapping(value = "/populatePersonDataFromServer.web", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
	public @ResponseBody
	List<PersonData> populateActivePSwapBasket() {

		PersonData personData = new PersonData();
		personData.setPersonId(10);
		personData.setPersonName("Java Honk");

		List<PersonData> personDatas = new ArrayList<PersonData>();
		personDatas.add(personData);

		personData = new PersonData();
		personData.setPersonId(11);
		personData.setPersonName("AngularJS dropdown");
		personDatas.add(personData);

		personData = new PersonData();
		personData.setPersonId(11);
		personData.setPersonName("Combo box sample");
		personDatas.add(personData);

		return personDatas;
	}

	@RequestMapping(value = "/getMapDataForChartMap.web", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
	public @ResponseBody HashMap<String, ChartData> getMapDataForChartMap() {
		

		HashMap<String, ChartData> hashmap = new HashMap<String, ChartData>();
		
		ChartData chartData = new ChartData();
		chartData.setDate(123L);
		chartData.setPostions(30);
		hashmap.put("key", chartData);
		
		chartData = new ChartData();
		chartData.setDate(123L);
		chartData.setPostions(30);
		hashmap.put("key2", chartData);
		return hashmap;
	}
	
	@RequestMapping(value = "/getMapDataForChart.web", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
	public @ResponseBody HashMap<String, String> getMapDataForChart() {
		

		HashMap<String, String> hashmap = new HashMap<String, String>();
		
		ChartData chartData = new ChartData();
		chartData.setDate(123L);
		chartData.setPostions(30);
		hashmap.put("key", "North America");
		hashmap.put("values", "North America2");
		
		
		return hashmap;
	}
	
	@RequestMapping(value = "/getJSONDataForChart.web", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE})
	public @ResponseBody String getJSONDataForChart() {
		

		JSONObject jo = new JSONObject();
		jo.put("values", new JSONArray(new Long[][]{{1025409600000L,23L},{1028088000000L,19L},{1030766400000L,21L},{1033358400000L,22L}}));		
		jo.put("key", "North America");
		
		JSONArray ja = new JSONArray();
		
		for (int i = 0; i < 10; i++) {
			ja.put(jo);
		}
		
		return ja.toString();	
	}

}
