package com.pci.unitoffer.server;

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

import com.isomorphic.datasource.BasicDataSource;
import com.isomorphic.datasource.DSRequest;
import com.isomorphic.datasource.DSResponse;

public class UserDataSource extends BasicDataSource
{

	public DSResponse executeFetch(DSRequest req) throws Exception
	{
		List records = fetchRecords(req.getCriteria());
		return new DSResponse(records);
	}

	private static List data = new ArrayList();
	private static int nextId;

	// Hard-coded data store
	static
	{
		String[] userName = { "Charles Madigen", "Ralph Brogan", "Grigori Ognev", "Tamara Kane",
				"Betsy Rosenbaum", "Gene Porter", "Prya Sambhus", "Ren Xian" };
		String[] jobTitle = { "Chief Operating Officer", "Manager Systems", "Technician",
				"Manager Site Services", "Secretary", "Manager Purchasing",
				"Line Worker", "Mobile Equipment Operator" };
		String[] email = { "charles.madigen", "ralph.brogan", "grigori.ognev", "tamara.kane",
				"elizabeth.rosenbaum", "gene.porter", "prya.sambhus", "ren.xian" };
		String[] type = { "full time", "contract", "part time", "full time", "part time",
				"contract", "part time", "full time" };
		float[] salary = { 20395, 18076, 12202, 21227, 11632, 17702, 12985, 16402 };

		for (int i = 0; i < userName.length; i++)
		{
			Map map = new HashMap();
			map.put("employeeId", new Integer(i + 1));
			map.put("userName", userName[i]);
			map.put("job", jobTitle[i]);
			map.put("email", email[i] + "@server.com");
			map.put("employeeType", type[i]);
			map.put("salary1", new Float(salary[i]));
			map.put("salary2", new Float(map.size()));

			data.add(map);
		}
		nextId = data.size() + 1;
	}

	// Returns full data list.
	// This sample does not support server side sorting/filtering.
	private List fetchRecords(Map criteria)
	{
		return data;
	}
}