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

namespace Gremlin.GremlinUtilities.GUClasses
{
    class DataIdType
    {
        private readonly string _dataType;
        private readonly List<string> _qualifiers;
        private List<string> _matchedQualifiers;
        private readonly int _numberOfQualifiers;
        private int _score = 0;
        private bool _allQualifierMatched = false;

        public string DataType 
        {
            get => _dataType;
        }

        public List<string> Qualifiers 
        {
            get => _qualifiers;
        }
        
        public int Score
        {
            get => _score;
        }
        
        public bool AllQualifierMatched
        {
            get => _allQualifierMatched;
        }

        public DataIdType(string DataType, IEnumerable<string> Qualifiers)
        {
            _dataType = DataType;
            _qualifiers = Qualifiers.ToList();
            _numberOfQualifiers = _qualifiers.Count;
            _matchedQualifiers = new();
        }

        public void AddFoundQualfier(string QualifierFound)
        {
            _matchedQualifiers.Add(QualifierFound);
            _score++;
            _allQualifierMatched = (_matchedQualifiers.Count == _numberOfQualifiers);
        }

        public bool CheckForQualifier(string qualifier)
        {
            return _qualifiers.Contains(qualifier);
        }

        public void IncreaseScore(int value = 1)
        {
            _score += value;
        }
        public void ResetScore()
        {
            _score = 0;
        }

        public override bool Equals(object obj)
        {
            return obj is DataIdType type 
                && _dataType == type._dataType;
        }

        public override int GetHashCode()
        {
            return HashCode.Combine(_dataType);
        }
    }
}
