using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Skyscraper.IO.CrazycatStreamReader;
using skyscraper5.src.Skyscraper.FrequencyListGenerator;

namespace skyscraper8.Skyscraper.FrequencyListGenerator
{
	public class BlindscanSearchResult
	{
		public SearchResult SearchResult;
		public STD_TYPE Standard { get; set; }
		public BlindscanResultState State { get; set; }
		public SearchResult2 SearchResult2;

		/// <summary>
		/// If true, the data is in SearchResult.
		/// If false, the data is in SearchResult2.
		/// </summary>
		public bool IsSatellite()
		{
				switch (Standard)
				{
					case STD_TYPE.STD_DVBS2: return true;
					case STD_TYPE.STD_DVBS: return true;
					case STD_TYPE.STD_DVBC: return false;
					case STD_TYPE.STD_DVBC2: return false;
					case STD_TYPE.STD_DVBT: return false;
					case STD_TYPE.STD_DVBT2: return false;
					case STD_TYPE.STD_AUTO: return true;
					default: throw new NotImplementedException(Standard.ToString());
				}
		}

		public long GetFrequency()
		{
			if (IsSatellite())
				return SearchResult.Freq;
			else
				return SearchResult2.Freq;
		}

		public char GetPolarity(int lnbTypeLofSw)
		{
			if (IsSatellite())
			{
				if (lnbTypeLofSw == 0 && SearchResult.Pol == 0)
					return 'L';
				else if (lnbTypeLofSw == 0 && SearchResult.Pol == 1)
					return 'R';
				else if (lnbTypeLofSw != 0 && SearchResult.Pol == 0)
					return 'H';
				else if (lnbTypeLofSw != 0 && SearchResult.Pol == 1)
					return 'V';
				else
					throw new NotImplementedException("Couldn't figure out signal polarity.");
			}
			else
			{
				return 'T';
			}
		}

		public int GetSymbolRate()
		{
			if (IsSatellite())
				return SearchResult.SR;
			else
				return SearchResult2.SR;
		}
	}
}
