package com.hp.isomorphic.client.issues;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.widgets.grid.ListGridRecord;

public class GridData extends DataSource {
	private static int id = 0;
	
	public static String getStatusValue() {
		Double r = Math.random() * 4;
		switch (r.intValue()) {
		case 3:
			return "Unknown";
		case 2:
			return "Error";
		case 1:
			return "Warning";
		default:
			return "OK";
		}
	}
	
	public static int getSortValue() {
		Double r = Math.random() * 1000;
		return r.intValue();
	}
	
	public static ListGridRecord createRecord() {
		ListGridRecord record = new ListGridRecord();
		record.setAttribute("idField", id);
		record.setAttribute("statusField", getStatusValue());
		record.setAttribute("contentField", "Content " + id);
		record.setAttribute("sortField", getSortValue());
		++id;
		return record;
	}
	
	public static ListGridRecord[] createRecords(int count) {
		ListGridRecord[] records = new ListGridRecord[count];
		for (int i = 0; i < count; ++i) {
			records[i] = createRecord();
		}
		return records;
	}
}
