using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Dvb.DataBroadcasting;
using skyscraper5.Skyscraper.Scraper;
using skyscraper5.src.InteractionChannel;
using skyscraper8.Skyscraper.Scraper;

namespace skyscraper8.GS
{
	public class GsContextDto
	{
		public GsContextMisDto MisClone(byte mis)
		{
			GsContextMisDto misClone = new GsContextMisDto(mis);

			Type type = this.GetType();
			PropertyInfo[] propertyInfos = type.GetProperties();
			foreach (PropertyInfo propertyInfo in propertyInfos)
			{
				object? value = propertyInfo.GetValue(this);
				propertyInfo.SetValue(misClone, value);
			}

			return misClone;
		}

		public byte GetMisId()
		{
			GsContextMisDto misDto = this as GsContextMisDto;
			if (misDto == null)
				return 0;
			return misDto.Mis;
		}

		public ISubTsHandler TsOutput { get; set; }
		public IMultiprotocolEncapsulationEventHandler IpOutput { get; set; }

		public InteractionChannelHandler Rcs2Output { get; set; }

		public ISkyscraperUiJunction UiJunction { get; internal set; }

		private Dictionary<ushort, ulong> trafficTypes;
		public void InformTrafficType(ushort trafficType)
		{
			if (trafficTypes == null)
				trafficTypes = new Dictionary<ushort, ulong>();
			
			if (!trafficTypes.ContainsKey(trafficType))
				trafficTypes.Add(trafficType, 1);
			else
				trafficTypes[trafficType]++;
		}
	}

	public class GsContextMisDto : GsContextDto
	{
		public byte Mis { get; }

		public GsContextMisDto(byte mis)
		{
			Mis = mis;
		}
	}
}
