package com.smartgwt.sample.server;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import com.isomorphic.datasource.DSRequest;
import com.isomorphic.datasource.DSResponse;
import com.isomorphic.util.DataTools;

public class BeanStructure {

	public static class Contract {
		private ArrayOfItem localItems;

		public ArrayOfItem getItems() {
			return localItems;
		}

		public void setItems(ArrayOfItem param) {
			this.localItems = param;
		}
	}

	public static class Item {
		protected EnDays localDays;
		protected TimeSeries localTimeSeries;

		public EnDays getDays() {
			return localDays;
		}

		public void setDays(EnDays param) {

			this.localDays = param;
		}

		public TimeSeries getTimeSeries() {
			return localTimeSeries;
		}

		public void setTimeSeries(TimeSeries param) {

			this.localTimeSeries = param;
		}

	}

	public static class TimeSeries {
		protected EnTimeSeriesPeriodType localSeriesType;
		protected ArrayOfKeyValueOfdateTimedouble localValues;
		
		public EnTimeSeriesPeriodType getSeriesType() {
			return localSeriesType;
		}

		public void setSeriesType(EnTimeSeriesPeriodType param) {
			this.localSeriesType = param;
		}

		public ArrayOfKeyValueOfdateTimedouble getValues() {
			return localValues;
		}

		public void setValues(ArrayOfKeyValueOfdateTimedouble param) {
			this.localValues = param;
		}

	}

	public static class KeyValueOfdateTimedouble_type0 {
		protected java.util.Calendar localKey;
		protected double localValue;

		public java.util.Calendar getKey() {
			return localKey;
		}

		public void setKey(java.util.Calendar param) {
			this.localKey = param;
		}

		public double getValue() {
			return localValue;
		}

		public void setValue(double param) {
			this.localValue = param;
		}

	}

	public static class ArrayOfItem {

		protected Item[] localItem;

		public Item[] getItem() {
			return localItem;
		}

		public void setItem(Item[] param) {
			this.localItem = param;
		}

	}

	public static class ArrayOfKeyValueOfdateTimedouble {

		protected KeyValueOfdateTimedouble_type0[] localKeyValueOfdateTimedouble;

		public KeyValueOfdateTimedouble_type0[] getKeyValueOfdateTimedouble() {
			return localKeyValueOfdateTimedouble;
		}

		public void setKeyValueOfdateTimedouble(KeyValueOfdateTimedouble_type0[] param) {
			this.localKeyValueOfdateTimedouble = param;
		}

	}

	public static class EnDays {
		protected EnDays_type0[] localEnDays_type0;

		public EnDays_type0[] getEnDays_type0() {
			return localEnDays_type0;
		}

		public void setEnDays_type0(EnDays_type0[] itemList) {
			this.localEnDays_type0 = itemList;
		}

		public java.lang.String toString() {
			java.lang.StringBuffer outString = new java.lang.StringBuffer();

			if (localEnDays_type0 != null) {
				for (int i = 0; i < localEnDays_type0.length; i++) {
					outString.append(localEnDays_type0[i].toString()).append(" ");
				}
			}

			return outString.toString().trim();
		}

	}

	public static class EnDays_type0 {
		@SuppressWarnings("rawtypes")
		private static java.util.HashMap _table_ = new java.util.HashMap();
		public static final java.lang.String _Monday = "Monday";
		public static final java.lang.String _Tuesday = "Tuesday";
		public static final java.lang.String _Wednesday = "Wednesday";
		public static final java.lang.String _Thursday = "Thursday";
		public static final java.lang.String _Friday = "Friday";
		public static final java.lang.String _Saturday = "Saturday";
		public static final java.lang.String _Sunday = "Sunday";
		public static final java.lang.String _All = "All";
		public static final EnDays_type0 Monday = new EnDays_type0(_Monday, true);
		public static final EnDays_type0 Tuesday = new EnDays_type0(_Tuesday, true);
		public static final EnDays_type0 Wednesday = new EnDays_type0(_Wednesday, true);
		public static final EnDays_type0 Thursday = new EnDays_type0(_Thursday, true);
		public static final EnDays_type0 Friday = new EnDays_type0(_Friday, true);
		public static final EnDays_type0 Saturday = new EnDays_type0(_Saturday, true);
		public static final EnDays_type0 Sunday = new EnDays_type0(_Sunday, true);
		public static final EnDays_type0 All = new EnDays_type0(_All, true);

		protected java.lang.String localEnDays_type0;

		protected EnDays_type0(java.lang.String value, boolean isRegisterValue) {
			localEnDays_type0 = value;

			if (isRegisterValue) {
				_table_.put(localEnDays_type0, this);
			}
		}

		public java.lang.String getValue() {
			return localEnDays_type0;
		}

		public boolean equals(java.lang.Object obj) {
			return (obj == this);
		}

		public int hashCode() {
			return toString().hashCode();
		}

		public java.lang.String toString() {
			return localEnDays_type0.toString();
		}

	}

	public static class EnTimeSeriesPeriodType {
		private static java.util.HashMap _table_ = new java.util.HashMap();
		public static final java.lang.String _Min5 = "Min5";
		public static final java.lang.String _Min15 = "Min15";
		public static final java.lang.String _Min60 = "Min60";
		public static final java.lang.String _Min1 = "Min1";
		public static final EnTimeSeriesPeriodType Min5 = new EnTimeSeriesPeriodType(_Min5, true);
		public static final EnTimeSeriesPeriodType Min15 = new EnTimeSeriesPeriodType(_Min15, true);
		public static final EnTimeSeriesPeriodType Min60 = new EnTimeSeriesPeriodType(_Min60, true);
		public static final EnTimeSeriesPeriodType Min1 = new EnTimeSeriesPeriodType(_Min1, true);

		/**
		 * field for EnTimeSeriesPeriodType
		 */
		protected java.lang.String localEnTimeSeriesPeriodType;

		// Constructor
		protected EnTimeSeriesPeriodType(java.lang.String value, boolean isRegisterValue) {
			localEnTimeSeriesPeriodType = value;

			if (isRegisterValue) {
				_table_.put(localEnTimeSeriesPeriodType, this);
			}
		}

		public java.lang.String getValue() {
			return localEnTimeSeriesPeriodType;
		}

		public boolean equals(java.lang.Object obj) {
			return (obj == this);
		}

		public int hashCode() {
			return toString().hashCode();
		}

		public java.lang.String toString() {
			return localEnTimeSeriesPeriodType.toString();
		}

	}
	
	//fetch method
	public DSResponse fetchContracts(DSRequest request) throws Exception {
		DSResponse resp = new DSResponse();
		Contract c = getContracts()[0];
		List<Contract> list = new ArrayList<Contract>();
		list.add(c);

		Map m = DataTools.getProperties(c);
		System.out.println( DataTools.prettyPrint(m));

		resp.setData(list);
		return resp;
	}

	public Contract[] getContracts() {
		Contract c = new Contract();
		ArrayOfItem items = new ArrayOfItem();
		items.setItem(createItems());
		c.setItems(items);
		Contract[] contracts = new Contract[1];
		contracts[0] = c;
		return contracts;
	}

	public Item[] createItems() {
		Item[] items = new Item[2];
		Item i1 = new Item();

		Item i2 = new Item();
		EnDays_type0[] en0 = new EnDays_type0[2];
		en0[0] = EnDays_type0.Monday;
		en0[1] = EnDays_type0.Saturday;
		EnDays days = new EnDays();
		days.setEnDays_type0(en0);
		i1.setDays(days);
		i2.setDays(days);
		i1.setTimeSeries(createTimeSeries(34.67));
		i2.setTimeSeries(createTimeSeries(800));
		items[0] = i1;
		items[1] = i2;

		return items;

	}

	public TimeSeries createTimeSeries(double val) {
		TimeSeries ts = new TimeSeries();
		ts.setSeriesType(EnTimeSeriesPeriodType.Min60);
		ts.setValues(createValues(val));
		return ts;
	}

	public ArrayOfKeyValueOfdateTimedouble createValues(double val) {
		ArrayOfKeyValueOfdateTimedouble arr = new ArrayOfKeyValueOfdateTimedouble();
		KeyValueOfdateTimedouble_type0[] kvPairs = new KeyValueOfdateTimedouble_type0[2];
		for (int i = 0; i < 2; i++) {
			KeyValueOfdateTimedouble_type0 kv = new KeyValueOfdateTimedouble_type0();
			kv.setKey(Calendar.getInstance());
			kv.setValue(val);
			kvPairs[i] = kv;
		}
		arr.setKeyValueOfdateTimedouble(kvPairs);
		return arr;
	}
}
