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

namespace Tutorial_5
{
    class WeatherData : ISubject
    {
        List<IWeatherObserver> observers;
        public void DeregisterObserver(IWeatherObserver observer)
        {
            if (observers.Contains(observer)) observers.Remove(observer);
            else Console.Error.WriteLine("{0} does not exist in the observers list.", observer.ToString());
        }

        public void NotifyObservers()
        {
            double t = GetTemperature();
            double h = GetHumidity();
            double p = GetPressure();

            foreach (var observer in observers)
            {
                observer.Update(t,h,p);
            }
        }

        public void RegisterObserver(IWeatherObserver observer)
        {
            if (observers.Contains(observer)) Console.Error.WriteLine("{0} already exists in the observers list.", observer.ToString());
            else observers.Add(observer);
        }

        public double GetTemperature()
        {
            return 0.0;
        }

        public double GetHumidity()
        {
            return 0.0;
        }

        public double GetPressure()
        {
            return 0.0;
        }

        void MeasurementChanged()
        {
            NotifyObservers();
        }

        public WeatherData()
        {
            observers = new List<IWeatherObserver>();
        }
    }
}
