using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NightScout
{
    public class NightscoutAlerter
    {
        public INightscoutDataSource DataSource { get; set; }
        public IAlerter Alerter { get; set; }
        public DateTime LastDataUpdateReceived { get; set; }

        public NightscoutAlerter(INightscoutDataSource dataSource, IAlerter alerter)
        {
            DataSource = dataSource;
            Alerter = alerter;
            SetupEvents();
        }

        private void SetupEvents()
        {
            DataSource.Connected += () => DataSource.Authorize();
            DataSource.Alarm += (alarm) => Alerter.StartAlert();
            DataSource.UrgentAlarm += (alarm) => Alerter.StartUrgentAlert();
            DataSource.ClearAlarm += (alarm) => Alerter.StopAlerts();
            DataSource.StaleDataAlarm += () => Alerter.StartStaleDataAlert();

            //DataSource.DataUpdate += DataSource_DataUpdate;
        }

        void DataSource_DataUpdate(object obj)
        {
            Console.WriteLine(obj);
        }

    }
}
