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

using System;
using CommunityServer.Components;


namespace CommunityServer.Components
{
	/// <summary>
	/// Common settings for conducting a search
	/// </summary>
	[Serializable]
	public class SearchQuery
	{
        public static SearchQuery FirstPageQuery(string textToFind)
        {
            SearchQuery query = new SearchQuery();
            query.PageIndex = 0;
            query.PageSize = 20;
            query.QueryText = textToFind;
            return query;
        }

        public static SearchQuery SectionSearch(string textToFind, int SectionID)
        {
            SearchQuery query = FirstPageQuery(textToFind);
            query.SectionsToSearch = new int[]{SectionID};
            return query;
        }


	    #region Private Members
		private int[] _groupsToSearch = null;
		private int[] _sectionsToSearch = null;
	    private string[] _tags = null;
		private ApplicationType[] _apptypes = null;
		private string _text;
		private int _pageSize;
		private int _pageIndex;
		private int _settingsID;
		private int _bestMatchSize = 500;
        private int[] _usersToSearch = null;
        private string[] _userNames = null;
        private SearchSort ss = SearchSort.Relevance;
        private DateTime _startDate, _endDate;
        private bool _logicallyOrTags = false;
        #endregion

        public SearchSort SortBy
        {
            get{return ss;}
            set{ss = value;}
        }

		public int[] GroupsToSearch
		{
			get {return _groupsToSearch;}
			set { _groupsToSearch = value;}
		}

		public int[] SectionsToSearch
		{
			get{return _sectionsToSearch;}
			set { _sectionsToSearch = value;}
		}

        public string[] Tags
        {
            get { return _tags; }
            set { _tags = value; }
        }
	    
        public string[] UserNamesToSearch
        {
            get{return _userNames;}
            set { _userNames = value;}
        }

		public ApplicationType[] ApplicationTypes
		{
			get { return _apptypes;}
			set {_apptypes = value;}
		}

		public string QueryText
		{
			get{return _text;}
			set {_text = value;}
		}

		public int PageSize
		{
			get{return _pageSize;}
			set {_pageSize = value;}
		}

		public int PageIndex
		{
			get{return _pageIndex;}
			set{_pageIndex = value;}
		}
			
		public int SettingsID
		{
			get{return _settingsID;}
			set{_settingsID = value;}
		}	

        public int[] UsersToSearch
        {
            get{return _usersToSearch;}
            set{_usersToSearch = value;}
        }
		
		public int BestMatchSize
		{
			get{return _bestMatchSize;}
			set{_bestMatchSize = value;}
		}
		
        public DateTime StartDate
        {
            get{return _startDate;}
            set{_startDate = value;}
        }

        public DateTime EndDate
        {
            get{return _endDate;}
            set{_endDate = value;}
        }

        public bool HasDate
        {
            get {return StartDate != DateTime.MinValue && EndDate != DateTime.MinValue;}
        }

        public bool HasTags
        {
            get{ return this.Tags != null && this.Tags.Length > 0;}
        }

        public bool LogicallyOrTags
        {
            get{ return _logicallyOrTags;}
            set{ _logicallyOrTags = value;}
        }

		
	}
}
