using System;
using System.Collections.Generic;
using System.IO;

namespace LeafWeb.Web.Charter
{
	[Serializable]
	public class PiscalOutput
	{
		// Each element will be a PiscalCurve element that contains
		// all of the output data for one curve.
		private readonly List<CurveData> _curveData; 

		public PiscalOutput()
		{
			_curveData = new List<CurveData>();
		}

		public bool ReadFromStream(StreamReader sr, ref String errorMsg)
		{
			// Skip the first two lines.
			sr.ReadLine();
			sr.ReadLine();
			var lineNbr = 2;

			// Now, there should be one or more rows, delimited by a row that has
			// CO2i in the first field.  Read in all of these rows.  The first field
			// in each row is the curve ID (input filename).

			var more = true;
			while (more)
			{
				var curve = new CurveData(sr, ref errorMsg, ref lineNbr);
				if (errorMsg.Length > 0)
					return false;

				_curveData.Add(curve);
				if (sr.EndOfStream)
					more = false;
			}
			return true;
		}

		public List<CurveData> GetCurveData()
		{
			return _curveData;
		}
	}
}