using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.TextCore.LowLevel;
namespace TMPro
{
    /// 
    /// Table that contains the various font features available for the given font asset.
    /// 
    [Serializable]
    public class TMP_FontFeatureTable
    {
        /// 
        /// List that contains the glyph multiple substitution records.
        /// 
        public List multipleSubstitutionRecords
        {
            get { return m_MultipleSubstitutionRecords; }
            set { m_MultipleSubstitutionRecords = value; }
        }
        /// 
        /// List that contains the glyph ligature records.
        /// 
        public List ligatureRecords
        {
            get { return m_LigatureSubstitutionRecords; }
            set { m_LigatureSubstitutionRecords = value; }
        }
        /// 
        /// List that contains the glyph pair adjustment records.
        /// 
        public List glyphPairAdjustmentRecords
        {
            get { return m_GlyphPairAdjustmentRecords; }
            set { m_GlyphPairAdjustmentRecords = value; }
        }
        /// 
        ///
        /// 
        public List MarkToBaseAdjustmentRecords
        {
            get { return m_MarkToBaseAdjustmentRecords; }
            set { m_MarkToBaseAdjustmentRecords = value; }
        }
        /// 
        ///
        /// 
        public List MarkToMarkAdjustmentRecords
        {
            get { return m_MarkToMarkAdjustmentRecords; }
            set { m_MarkToMarkAdjustmentRecords = value; }
        }
        // =============================================
        // Private backing fields for public properties.
        // =============================================
        [SerializeField]
        internal List m_MultipleSubstitutionRecords;
        [SerializeField]
        internal List m_LigatureSubstitutionRecords;
        [SerializeField]
        internal List m_GlyphPairAdjustmentRecords;
        [SerializeField]
        internal List m_MarkToBaseAdjustmentRecords;
        [SerializeField]
        internal List m_MarkToMarkAdjustmentRecords;
        // =============================================
        // Lookup data structures.
        // =============================================
        internal Dictionary> m_LigatureSubstitutionRecordLookup;
        internal Dictionary m_GlyphPairAdjustmentRecordLookup;
        internal Dictionary m_MarkToBaseAdjustmentRecordLookup;
        internal Dictionary m_MarkToMarkAdjustmentRecordLookup;
        // =============================================
        // Constructor(s)
        // =============================================
        public TMP_FontFeatureTable()
        {
            m_LigatureSubstitutionRecords = new List();
            m_LigatureSubstitutionRecordLookup = new Dictionary>();
            m_GlyphPairAdjustmentRecords = new List();
            m_GlyphPairAdjustmentRecordLookup = new Dictionary();
            m_MarkToBaseAdjustmentRecords = new List();
            m_MarkToBaseAdjustmentRecordLookup = new Dictionary();
            m_MarkToMarkAdjustmentRecords = new List();
            m_MarkToMarkAdjustmentRecordLookup = new Dictionary();
        }
        // =============================================
        // Utility Functions
        // =============================================
        /// 
        /// Sort the glyph pair adjustment records by glyph index.
        /// 
        public void SortGlyphPairAdjustmentRecords()
        {
            // Sort List of Kerning Info
            if (m_GlyphPairAdjustmentRecords.Count > 0)
                m_GlyphPairAdjustmentRecords = m_GlyphPairAdjustmentRecords.OrderBy(s => s.firstAdjustmentRecord.glyphIndex).ThenBy(s => s.secondAdjustmentRecord.glyphIndex).ToList();
        }
        /// 
        /// Sort the Mark-to-Base Adjustment Table records.
        /// 
        public void SortMarkToBaseAdjustmentRecords()
        {
            // Sort List of Kerning Info
            if (m_MarkToBaseAdjustmentRecords.Count > 0)
                m_MarkToBaseAdjustmentRecords = m_MarkToBaseAdjustmentRecords.OrderBy(s => s.baseGlyphID).ThenBy(s => s.markGlyphID).ToList();
        }
        /// 
        /// Sort the Mark-to-Mark Adjustment Table records.
        /// 
        public void SortMarkToMarkAdjustmentRecords()
        {
            // Sort List of Kerning Info
            if (m_MarkToMarkAdjustmentRecords.Count > 0)
                m_MarkToMarkAdjustmentRecords = m_MarkToMarkAdjustmentRecords.OrderBy(s => s.baseMarkGlyphID).ThenBy(s => s.combiningMarkGlyphID).ToList();
        }
    }
}