using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

using EQNetwork.Utility;
using EQNetwork.Aspects;

namespace EQNetwork.Objects
{
    public class ParameterBlock_User_ListCollections : PropertyChangeTracker
    {
        public enum SortOrder
        {
            Alpha,
            Recent,
            Popularity,
            Comments,
        };

        // OPTIONS (all one way... sent to backend)

        /// <summary>
        /// User whose collections to list (null uses session user)
        /// </summary>
        [TrackPropertyChanged()]
        public int? UserId { get; set; }

        /// <summary>
        /// Limit results to Names or Descriptions that match this search string
        /// </summary>
        [TrackPropertyChanged()]
        public string Search { get; set; }

        /// <summary>
        /// Limit results to Categories in this list
        /// </summary>
        [TrackPropertyChanged()]
        public List<string> Categories { get; set; }

        /// <summary>
        /// Limit results to Names that begin with this prefix
        /// </summary>
        [TrackPropertyChanged()]
        public string HasPrefix { get; set; }

        /// <summary>
        /// Limit results to include or not include adult content
        /// </summary>
        [TrackPropertyChanged()]
        public bool? IncludeAdult { get; set; }

        /// <summary>
        /// Limit results to include or not include empty Collections
        /// </summary>
        [TrackPropertyChanged()]
        public bool? IncludeEmpty { get; set; }

        /// <summary>
        /// Limit results to include or not include these User_CollectionTypes (e.g. 
        /// </summary>
        [TrackPropertyChanged()]
        [SerializeWith("User_CollectionTypeIds")]
        public List<Db.User_CollectionType> User_CollectionTypes { get; set; }

        public string User_CollectionTypeIds
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                foreach (var item in User_CollectionTypes)
                {
                    if (sb.Length > 0) sb.Append(",");
                    sb.Append((int)item);
                }
                return sb.ToString();
            }
        }

        /// <summary>
        /// Limit results to include or not include Users that are being followed (as pseudo collection items)
        /// </summary>
        [TrackPropertyChanged()]
        public bool? includeUsers { get; set; }

        /// <summary>
        /// Sort order 
        /// </summary>
        [TrackPropertyChanged()]
        public string OrderBy { get; set; }

        /// <summary>
        /// Limits results by ordinal position - for paging support (starts at 1 not 0)
        /// </summary>
        public int? Page { get; set; }

        /// <summary>
        /// Limits results by ordinal position - for paging support
        /// </summary>
        public int? PageSize { get; set; }

        // Note: Page and PageSize will be replaced with Start and End in the actual API call

        /// <summary>
        /// Limits results by ordinal position - for paging support (starts at 1 not 0)
        /// </summary>
        [TrackPropertyChanged()]
        public int? Start { get; private set; }

        /// <summary>
        /// Limits results by ordinal position - for paging support (starts at 1 not 0)
        /// </summary>
        [TrackPropertyChanged()]
        public int? End { get; private set; }

        /// <summary>
        /// Sorts results so that collections with notifications show up first
        /// </summary>
        [TrackPropertyChanged()]
        public bool? NotificationCountInSort { private get; set; }

        /// <summary>
        /// If collection list is passed in... results will be appended
        /// </summary>
        public CollectionList CollectionList { get; set; }

        public ParameterBlock_User_ListCollections()
        {
            User_CollectionTypes = new List<Db.User_CollectionType>() { Db.User_CollectionType.Owner };
        }

        public void ReadyForParms()
        {
            // convert page and pagesize to start and end
            if (Page == null)
                Page = 1;
            if (PageSize == null)
                PageSize = 10;
            Start = (Page - 1) * PageSize + 1;
            End = Start + PageSize;
        }
    }

}
