using System;
using System.Collections.Generic;
using System.Text;

namespace Medivators.BusinessObjects
{
	//	Class exists to simplify data for the stupid grid. 
	//	No fields, data elements are all properties, and 
	//	there is no object nesting. No methods and no logic
	//	that is not employed right in the constructor

	public class LogDisplayRecord
	{
		private DeviceRecordTypes _recordType;
		private bool _isAlarm;
		private long _logNumber;
		private long _machineID;
		private string _station;
		private string _text;
		private int _program;
		private DateTime _timestamp;
		private string _data;
		private string _sortKey;

		public LogDisplayRecord(IBusinessObject DeviceRecord)
		{
			Type t = DeviceRecord.GetType();
			if (t.Equals(typeof(DeviceRecord)) || t.IsSubclassOf(typeof(DeviceRecord)))
			{
				this.RecordType = ((DeviceRecord)DeviceRecord).RecordType;
				this.IsAlarm = ((DeviceRecord)DeviceRecord).IsAlarm;
				this.LogNumber = ((DeviceRecord)DeviceRecord).LogNumber;
				this.MachineID = ((DeviceRecord)DeviceRecord).MachineID;
				this.Station = ((DeviceRecord)DeviceRecord).Station;
				this.Text = ((DeviceRecord)DeviceRecord).Text;
			}
			if (t.Equals(typeof(DSD201HeaderRecord)) || t.IsSubclassOf(typeof(DSD201HeaderRecord)))
			{
				this.Data = ((DSD201HeaderRecord)DeviceRecord).Data;
			}
			if (t.Equals(typeof(DSD201EventRecord)) || t.IsSubclassOf(typeof(DSD201EventRecord)))
			{
				this.Program = ((DSD201EventRecord)DeviceRecord).Program;
				this.Timestamp = ((DSD201EventRecord)DeviceRecord).Timestamp;
			}
			if (t.Equals(typeof(TimestampedHeaderRecord)) || t.IsSubclassOf(typeof(TimestampedHeaderRecord)))
			{
				this.Timestamp = ((TimestampedHeaderRecord)DeviceRecord).Timestamp;
			}
			this.SortKey = this.Timestamp.ToString("yyyyMMddHHmmss") + this.LogNumber.ToString("000000");
		}

		public string SortKey
		{
			get { return _sortKey; }
			set { _sortKey = value; }
		}
		public DeviceRecordTypes RecordType
		{
			get { return _recordType; }
			set { _recordType = value; }
		}
		public bool IsAlarm
		{
			get { return _isAlarm; }
			set { _isAlarm = value; }
		}
		public long LogNumber
		{
			get { return _logNumber; }
			set { _logNumber = value; }
		}
		public long MachineID
		{
			get { return _machineID; }
			set { _machineID = value; }
		}
		public string Station
		{
			get { return _station; }
			set { _station = value; }
		}
		public string Text
		{
			get { return _text; }
			set { _text = value; }
		}
		public int Program
		{
			get { return _program; }
			set { _program = value; }
		}
		public DateTime Timestamp
		{
			get { return _timestamp; }
			set { _timestamp = value; }
		}
		public string Data
		{
			get { return _data; }
			set { _data = value; }
		}
	}
}
