using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;

namespace ParticulateSensorRecords
{
    public class LocationList : IEnumerable<Location>
    {
        // Declare private list for locations
        public List<Location> Locations { get; set; }

        public LocationList()
        {
            this.Locations = new List<Location>();
        }

        public List<String> CalculateLocationTotal()
        {
            List<String> locationParticulateList = new List<string>();

            var locationTotals =
                from location in this.Locations
                from airData in location.AirDatas
                group airData by airData.Date into dates
                let totalValues = (from aird in dates
                                   select
             (int)aird.Particulate).Sum()
                orderby totalValues descending
                select new
                {
                    AirDate = dates.Key,
                    TotalValues = totalValues
                };

            foreach (var l in locationTotals)
            {
                locationParticulateList.Add(String.Format("Date: {0}, Particulate: {1}", l.AirDate.ToShortDateString(), l.TotalValues));

            }

            return locationParticulateList;
        }

        public IEnumerator<Location> GetEnumerator()
        {
            return Locations.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return Locations.GetEnumerator();
        }
    }   
}