//-----------------------------------------------------------------------
// 
//     Copyright (c) Microsoft Corporation.
// 
//-----------------------------------------------------------------------
namespace Microsoft.Isam.Esent.Interop
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Diagnostics;
    using System.Globalization;
    using System.Text;
    /// 
    /// Information about one esent index. This is not an interop
    /// class, but is used by the meta-data helper methods.
    /// 
    [Serializable]
    public class IndexInfo
    {
        /// 
        /// The name of the index.
        /// 
        private readonly string name;
        /// 
        /// The culture info of the index.
        /// 
        private readonly CultureInfo cultureInfo;
        /// 
        /// Index comparison options.
        /// 
        private readonly CompareOptions compareOptions;
        /// 
        /// Index segments.
        /// 
        private readonly ReadOnlyCollection indexSegments;
        /// 
        /// Index options.
        /// 
        private readonly CreateIndexGrbit grbit;
        /// 
        /// Number of unique keys in the index.
        /// 
        private readonly int keys;
        /// 
        /// Number of entries in the index.
        /// 
        private readonly int entries;
        /// 
        /// Number of pages in the index.
        /// 
        private readonly int pages;
        /// 
        /// Initializes a new instance of the IndexInfo class.
        /// 
        /// Name of the index.
        /// CultureInfo for string sorting.
        /// String comparison options.
        /// Array of index segment descriptions.
        /// Index options.
        /// Number of unique keys in the index.
        /// Number of entries in the index.
        /// Number of pages in the index.
        internal IndexInfo(
            string name,
            CultureInfo cultureInfo,
            CompareOptions compareOptions,
            IndexSegment[] indexSegments,
            CreateIndexGrbit grbit,
            int keys,
            int entries,
            int pages)
        {
            this.name = name;
            this.cultureInfo = cultureInfo;
            this.compareOptions = compareOptions;
            this.indexSegments = new ReadOnlyCollection(indexSegments);
            this.grbit = grbit;
            this.keys = keys;
            this.entries = entries;
            this.pages = pages;
        }
        /// 
        /// Gets the name of the index.
        /// 
        public string Name
        {
            [DebuggerStepThrough]
            get { return this.name; }
        }
        /// 
        /// Gets the CultureInfo the index is sorted by.
        /// 
        public CultureInfo CultureInfo
        {
            [DebuggerStepThrough]
            get { return this.cultureInfo; }
        }
        /// 
        /// Gets the CompareOptions for the index.
        /// 
        public CompareOptions CompareOptions
        {
            [DebuggerStepThrough]
            get { return this.compareOptions; }
        }
        /// 
        /// Gets the segments of the index.
        /// 
        public IList IndexSegments
        {
            [DebuggerStepThrough]
            get { return this.indexSegments; }
        }
        /// 
        /// Gets the index options.
        /// 
        public CreateIndexGrbit Grbit
        {
            [DebuggerStepThrough]
            get { return this.grbit; }
        }
        /// 
        /// Gets the number of unique keys in the index.
        /// This value is not current and is only is updated by Api.JetComputeStats.
        /// 
        public int Keys
        {
            [DebuggerStepThrough]
            get { return this.keys; }
        }
        /// 
        /// Gets the number of entries in the index.
        /// This value is not current and is only is updated by Api.JetComputeStats.
        /// 
        public int Entries
        {
            [DebuggerStepThrough]
            get { return this.entries; }
        }
        /// 
        /// Gets the number of pages in the index.
        /// This value is not current and is only is updated by Api.JetComputeStats.
        /// 
        public int Pages
        {
            [DebuggerStepThrough]
            get { return this.pages; }
        }
        /// 
        /// Returns a  that represents the current .
        /// 
        /// 
        /// A  that represents the current .
        /// 
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(this.Name);
            sb.Append(" (");
            foreach (var segment in this.IndexSegments)
            {
                sb.Append(segment.ToString());
            }
            sb.Append(")");
            return sb.ToString();
        }
    }
}