using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace EditGrid.Models
{
    public class DatedEnergy
    {
        public DateTime Date { get; set; }

        [UIHint("Number")]
        public double Etoday { get; set; }

        public bool Edited { get; set; }
    }

    public static class DataStore
    {
        public static List<DatedEnergy> Yield = new List<DatedEnergy>
                {
                    new DatedEnergy {Date = new DateTime(2013, 11, 1), Etoday = 10.0, Edited = false},
                    new DatedEnergy {Date = new DateTime(2013, 11, 2), Etoday = 21.5, Edited = false},
                    new DatedEnergy {Date = new DateTime(2013, 11, 3), Etoday = 35, Edited = false},
                    new DatedEnergy {Date = new DateTime(2013, 11, 4), Etoday = 40, Edited = false},
                    new DatedEnergy {Date = new DateTime(2013, 11, 5), Etoday = 50.1, Edited = false},
                    new DatedEnergy {Date = new DateTime(2013, 11, 6), Etoday = 0, Edited = false},
                    new DatedEnergy {Date = new DateTime(2013, 11, 7), Etoday = 70, Edited = false},
                    new DatedEnergy {Date = new DateTime(2013, 11, 8), Etoday = 8.07, Edited = false},
                    new DatedEnergy {Date = new DateTime(2013, 11, 9), Etoday = 9.81, Edited = false},
                    new DatedEnergy {Date = new DateTime(2013, 11, 10), Etoday = 10.1, Edited = false}
                };
    }

    public class MonthlyYieldModel
    {

        public List<DatedEnergy> Yield { get; set; }

        public MonthlyYieldModel()
        {
            var refDate = DateTime.Now;
            Yield = DataStore.Yield;
            //Yield = new List<DatedEnergy>
            //    {
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 1), Etoday = 10.0, Edited = false},
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 2), Etoday = 21.5, Edited = false},
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 3), Etoday = 35, Edited = false},
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 4), Etoday = 40, Edited = false},
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 5), Etoday = 50.1, Edited = false},
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 6), Etoday = 0, Edited = false},
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 7), Etoday = 70, Edited = false},
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 8), Etoday = 8.07, Edited = false},
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 9), Etoday = 9.81, Edited = false},
            //        new DatedEnergy {Date = new DateTime(refDate.Year, refDate.Month, 10), Etoday = 10.1, Edited = false}
            //    };
        }

        public MonthlyYieldModel(DateTime refDate)
        {
            var inverters = new List<Guid> {new Guid("1f577122-740b-4fed-b1af-ede10b43f8fd")};
                //, new Guid("cd15460d-6aae-4da1-933f-f0ebf3532f83") };


            var startDate = new DateTime(refDate.Year, refDate.Month, 1);
            var endDate = new DateTime(refDate.Year, refDate.Month + 1, 1).AddMinutes(-1);

            //OperationContext.Current.SetAuthorizationHeader(token);

            //var items = client.ReadDailyEnergyEnriched(inverters, startDate, endDate).Items;

            //items = items.Where(item => item.InverterId == inverters[0]).ToList();

            //Yield = (from item in items
            //select new DatedEnergy {Date = item.TimeStamp, Etoday = item.Value, Edited = false}).ToList();


        }
    }
}