using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace Toolbox.Docking.Api.Objects.Profiler
{

    /// <summary>
    /// Definition of profiling categories list.
    /// </summary>
    [Serializable]
    public sealed class TbProfilingCategories
    {
        private readonly List<TbProfilingCategoryNode> _childList;

        /// <summary>
        /// Constructor for the profiler catogories list. 
        /// </summary>
        /// <param name="categories">Enumeration of the profiling categories.</param>
        /// <param name="isSorted">Specifies if the profiler has a preferred sort order for the categories list (to override Toolbox sorting).</param>
        /// <param name="counterCategory">Counter category is assigned when no category can be possitivelly assigned to a chemical.</param>
        public TbProfilingCategories(IEnumerable<TbProfilingCategoryNode> categories, bool isSorted,
            string counterCategory)
        {
            _childList = new List<TbProfilingCategoryNode>();
            if (categories != null)
                _childList.AddRange(categories);
            IsSorted = isSorted;
            CounterCategory = counterCategory;
        }

        /// <summary>
        /// Constructor for the profiler catogories list. 
        /// </summary>
        /// <param name="categories">Enumeration of the profiling categories.</param>
        /// <param name="version">Versioned category list.</param>
        /// <param name="isSorted">Specifies if the profiler has a preferred sort order for the categories list (to override Toolbox sorting).</param>
        /// <param name="counterCategory">Counter category is assigned when no category can be possitivelly assigned to a chemical.</param>
        public TbProfilingCategories(IEnumerable<string> categories, int version, bool isSorted,
            string counterCategory) : this(null, isSorted, counterCategory)
        {
            _childList.AddRange(categories.Select(cat => new TbProfilingCategoryNode(cat, version, Color.Black, null)));
        }


        /// <summary>
        /// If true the categoris are sorted by specific order and shoud not be re-sorted by the system alphabetically.
        /// </summary>
        public bool IsSorted { get; }

        /// <summary>
        /// Counter category is assigned when no category can be possitivelly assigned to a chemical.
        /// </summary>
        public string CounterCategory { get; }

        /// <summary>
        /// Property for accessing the categories list.
        /// </summary>
        public IReadOnlyList<TbProfilingCategoryNode> ChildList => _childList;
    }

}