//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;

namespace CommunityServer.Components {
    /// <summary>
    /// Summary description for UserSet.
    /// </summary>
    [Serializable]
	public class ThreadSet {

        ArrayList threads = new ArrayList();
        ArrayList announcements = new ArrayList();
		SortedList pageIndex = new SortedList();
		int totalRecords = 0;

        public int TotalRecords {
            get {
                return totalRecords;
            }
            set {
                totalRecords = value;
            }
        }

        public ArrayList Threads {
            get {
                return threads;
            }
			set
			{
				threads = value;
			}
        }

		public SortedList PageIndex 
		{
			get 
			{
				return pageIndex;
			}
			set
			{
				pageIndex = value;
			}
		}

        public ArrayList Announcements 
		{
            get {
                if (announcements.Count > 0)
                    return announcements;

                // Announcements hasn't been asked for
                // Split thread and announcements
                FilterAnnouncements();

                return announcements;
            }
			set
			{
				threads = value;
			}
        }

        public bool HasResults {
            get {
                if (threads.Count > 0)
                    return true;
                return false;
            }
        }

        private void FilterAnnouncements() {
            ArrayList _threads = new ArrayList();

            foreach (IThread t in threads) {

                if (t.IsAnnouncement)
                    announcements.Add(t);
                else
                    _threads.Add(t);

            }

            // All done
            //
            threads = _threads;

        }

    }
}
