using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using LinqToTwitter;

namespace Azyobuzi.Twirunrun
{
    public class RecentStatusesCollection : ObservableCollection<StatusInfo>
    {
        private RecentStatusesCollection() { }

        private static RecentStatusesCollection instance;
        public static RecentStatusesCollection Instance
        {
            get
            {
                if (instance == null)
                    instance = new RecentStatusesCollection();

                return instance;
            }
        }

        public void AddRange(IEnumerable<StatusInfo> collection)
        {
            var sourceList = collection.ToList();

            sourceList.ForEach(item => Items.Add(item));

            OnPropertyChanged(new PropertyChangedEventArgs("Count"));
            OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
            OnCollectionChanged(
                new NotifyCollectionChangedEventArgs(
                    NotifyCollectionChangedAction.Add,
                    sourceList
                )
            );
        }
    }
}
