using System.Collections.Concurrent;
using MediaBrowser.Controller.Entities;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Library
{
    /// 
    /// Class ChildrenChangedEventArgs
    /// 
    public class ChildrenChangedEventArgs : EventArgs
    {
        /// 
        /// Gets or sets the folder.
        /// 
        /// The folder.
        public Folder Folder { get; set; }
        /// 
        /// Gets or sets the items added.
        /// 
        /// The items added.
        public ConcurrentBag ItemsAdded { get; set; }
        /// 
        /// Gets or sets the items removed.
        /// 
        /// The items removed.
        public List ItemsRemoved { get; set; }
        /// 
        /// Gets or sets the items updated.
        /// 
        /// The items updated.
        public ConcurrentBag ItemsUpdated { get; set; }
        /// 
        /// Create the args and set the folder property
        /// 
        /// The folder.
        /// 
        public ChildrenChangedEventArgs(Folder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException();
            }
            //init the folder property
            Folder = folder;
            //init the list
            ItemsAdded = new ConcurrentBag();
            ItemsRemoved = new List();
            ItemsUpdated = new ConcurrentBag();
        }
        /// 
        /// Adds the new item.
        /// 
        /// The item.
        /// 
        public void AddNewItem(BaseItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }
            
            ItemsAdded.Add(item);
        }
        /// 
        /// Adds the updated item.
        /// 
        /// The item.
        /// 
        public void AddUpdatedItem(BaseItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }
            
            ItemsUpdated.Add(item);
        }
        /// 
        /// Adds the removed item.
        /// 
        /// The item.
        /// 
        public void AddRemovedItem(BaseItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }
            ItemsRemoved.Add(item);
        }
        /// 
        /// Lists the has change.
        /// 
        /// The list.
        /// true if XXXX, false otherwise
        private bool ListHasChange(List list)
        {
            return list != null && list.Count > 0;
        }
        /// 
        /// Lists the has change.
        /// 
        /// The list.
        /// true if XXXX, false otherwise
        private bool ListHasChange(ConcurrentBag list)
        {
            return list != null && !list.IsEmpty;
        }
        
        /// 
        /// Gets a value indicating whether this instance has change.
        /// 
        /// true if this instance has change; otherwise, false.
        public bool HasChange
        {
            get { return HasAddOrRemoveChange || ListHasChange(ItemsUpdated); }
        }
        /// 
        /// Gets a value indicating whether this instance has add or remove change.
        /// 
        /// true if this instance has add or remove change; otherwise, false.
        public bool HasAddOrRemoveChange
        {
            get { return ListHasChange(ItemsAdded) || ListHasChange(ItemsRemoved); }
        }
    }
}