using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper;
using skyscraper5.Skyscraper.IO;
using skyscraper5.Skyscraper.Plugins;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper5.src.InteractionChannel.Model.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0xa9,"RMT")]
	public class _0xa9_SatelliteReturnLinkDescriptor : TsDescriptor
	{
		public _0xa9_SatelliteReturnLinkDescriptor(byte[] bytes)
		{
			MemoryStream ms = new MemoryStream(bytes, false);
			SatelliteId = ms.ReadUInt8();
			BeamId = ms.ReadUInt16BE();
			GatewayId = ms.ReadUInt8();
			byte reserved = ms.ReadUInt8();
			OrbitalPosition = ms.ReadUInt16BE();
			Eastern = ((ms.ReadUInt8() & 0x01) != 0);
			SuperframeId = ms.ReadUInt8();
			TxFrequencyOffset = ms.ReadUInt24BE();
			PrivateDataBytes = ms.ReadBytes(ms.GetAvailableBytes());
			Valid = true;
		}

		public byte SatelliteId { get; }
		public ushort BeamId { get; }
		public byte GatewayId { get; }
		public ushort OrbitalPosition { get; }
		public bool Eastern { get; }
		public byte SuperframeId { get; }
		public uint TxFrequencyOffset { get; }
		public byte[] PrivateDataBytes { get; }

		public override string ToString()
		{
			return String.Format("Return Link: Sat-ID {0}, Beam-ID {1}, Gateway-ID {2}, Superframe-ID {3}, Freq-Offset {4}", SatelliteId, BeamId, GatewayId, SuperframeId, TxFrequencyOffset);
		}

		protected bool Equals(_0xa9_SatelliteReturnLinkDescriptor other)
		{
			return SatelliteId == other.SatelliteId && BeamId == other.BeamId && GatewayId == other.GatewayId && OrbitalPosition == other.OrbitalPosition && Eastern == other.Eastern && SuperframeId == other.SuperframeId && TxFrequencyOffset == other.TxFrequencyOffset;
		}

		public override bool Equals(object? obj)
		{
			if (ReferenceEquals(null, obj)) 
				return false;
			if (ReferenceEquals(this, obj)) 
				return true;
			if (obj.GetType() != this.GetType()) 
				return false;
			return Equals((_0xa9_SatelliteReturnLinkDescriptor)obj);
		}

		public override int GetHashCode()
		{
			return HashCode.Combine(SatelliteId, BeamId, GatewayId, OrbitalPosition, Eastern, SuperframeId, TxFrequencyOffset);
		}
	}
}
