using System;
using System.Collections.Generic;

namespace QTMDataFormat;

public class TypePrecedenceRuleImplementer
{
	private Dictionary<Type, int> precedenceInfo;

	public TypePrecedenceRuleImplementer()
	{
		precedenceInfo = new Dictionary<Type, int>();
		ResetPrecedenceInformation();
	}

	public Type GetTypeByPrecedence(Type newType, Type oldType)
	{
		int num = 0;
		int num2 = 0;
		if (precedenceInfo.ContainsKey(newType))
		{
			num = precedenceInfo[newType];
		}
		if (precedenceInfo.ContainsKey(oldType))
		{
			num2 = precedenceInfo[oldType];
		}
		if (num <= num2)
		{
			return oldType;
		}
		return newType;
	}

	private void ResetPrecedenceInformation()
	{
		precedenceInfo.Add(typeof(string), 5);
		precedenceInfo.Add(typeof(double), 4);
		precedenceInfo.Add(typeof(float), 3);
		precedenceInfo.Add(typeof(long), 2);
		precedenceInfo.Add(typeof(int), 1);
	}
}
