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

namespace Gremlin.GremlinUtilities.GUClasses
{
	internal class DataIdType
	{
		private readonly List<string> _matchedQualifiers;
		private readonly int _numberOfQualifiers;

		public string DataType { get; }

		public List<string> Qualifiers { get; }

		public int Score { get; private set; } = 0;

		public bool AllQualifierMatched { get; private set; } = false;

		public DataIdType(string DataType, IEnumerable<string> Qualifiers)
		{
			this.DataType = DataType;
			this.Qualifiers = Qualifiers.ToList();
			_numberOfQualifiers = this.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);
		}
	}
}
