package com.hp.isomorphic.client.issues;

import java.util.ArrayList;
import java.util.List;

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

public class GridData extends DataSource {
	private static Integer 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.toString());
		record.setAttribute("statusField", getStatusValue());
		record.setAttribute("contentField", "Content " + id);
		record.setAttribute("sortField", getSortValue());
		
		for (int i = 0; i < 30; ++i) {
			record.setAttribute("column" + i, "Data " + i);
		}

		++id;
		return record;
	}
	
	public static RecordList createRecordList(int count) {
		List<ListGridRecord> records = new ArrayList<>();
		for (int i = 0; i < count; ++i) {
			records.add(createRecord());
		}
		return new RecordList(records);
	}
}
