using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TelerikTestReal
{
	public enum TestType : int
	{
		None = 0,
		RefRovina = 1,
		FiOffset = 2,
		AbsVyska = 3,
		RelVyska = 4,
		RozdielVysky = 5,
		RozdielVyskyOblast = 6,
		TestNitu = 7,
		TestZatky = 8,
		TestKolika = 9,
	}

	public class TestParSubItem
	{
		public string Code { get; set; }
		public float Min { get; set; }
		public float Max { get; set; }
		public bool Disabled { get; set; }

		public TestParSubItem()
		{
			Code = "";
		}

	}

	public class TestParItem
	{
		public string Code { get; set; }
		public float R { get; set; }
		public float Fi { get; set; }
		public float Min { get; set; }
		public float Max { get; set; }
		public string Comment { get; set; }
		public bool Disabled { get; set; }

		// Test Type
		private TestType _testType;
		public TestType TestType
		{
			get => _testType;
			set
			{
				if (_testType == value)
					return;

				int newSubCnt = GetSubItemCount(value);
				if (newSubCnt != SubItems.Count)
					SubItems = CreateSubItems(newSubCnt);

				_testType = value;
			}
		}

		private List<TestParSubItem> CreateSubItems(int cnt)
		{
			var subs = new List<TestParSubItem>();
			if (cnt == 0)
				return subs;

			for (int i = 0; i < cnt; i++)
			{
				var sub = new TestParSubItem();
				sub.Code = $"{Code}.{i + 1}";
				subs.Add(sub);
			}

			return subs;
		}

		private int GetSubItemCount(TestType testType)
		{
			switch (testType)
			{
				case TestType.TestNitu:
					return 4;
				case TestType.TestZatky:
				case TestType.TestKolika:
					return 2;
				default:
					return 0;
			}
		}

		// Sub Items
		public List<TestParSubItem> SubItems { get; private set; } = new List<TestParSubItem>();
		public bool HasSubItems => SubItems.Count > 0;
		public int SubItemsCount => SubItems.Count;


		public TestParItem()
		{
			Code = "";
			Comment = "";
		}
	}
}
