using skyscraper8.DvbNip;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper8.Skyscraper.Scraper.Storage.Utilities
{
	public class DatabaseKeyNipMulticastGatewayConfigurationTransportSession
	{

		public DatabaseKeyNipMulticastGatewayConfigurationTransportSession(NipActualCarrierInformation carrier, MulticastEndpointAddressType address)
		{
			this.CarrierId = carrier.NipCarrierId;
			this.LinkId = carrier.NipLinkId;
			this.NetworkId = carrier.NipNetworkId;
			this.ServiceId = carrier.NipServiceId;
			if (!string.IsNullOrEmpty(address.NetworkSourceAddress))
			{
				this.SourceAddress = IPAddress.Parse(address.NetworkSourceAddress);
			}

			this.DestinationAddress = IPAddress.Parse(address.NetworkDestinationGroupAddress);
			this.DestinationPort = ushort.Parse(address.TransportDestinationPort);
			this.TSI = long.Parse(address.MediaTransportSessionIdentifier);
		}

		public long TSI { get; set; }

		public ushort DestinationPort { get; set; }

		public IPAddress DestinationAddress { get; set; }

		public IPAddress SourceAddress { get; set; }

		public ushort ServiceId { get; set; }

		public ushort NetworkId { get; set; }

		public ushort LinkId { get; set; }

		public ushort CarrierId { get; set; }

		protected bool Equals(DatabaseKeyNipMulticastGatewayConfigurationTransportSession other)
		{
			return TSI == other.TSI && DestinationPort == other.DestinationPort && DestinationAddress.Equals(other.DestinationAddress) && SourceAddress.Equals(other.SourceAddress) && ServiceId == other.ServiceId && NetworkId == other.NetworkId && LinkId == other.LinkId && CarrierId == other.CarrierId;
		}

		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((DatabaseKeyNipMulticastGatewayConfigurationTransportSession)obj);
		}

		public override int GetHashCode()
		{
			return HashCode.Combine(TSI, DestinationPort, DestinationAddress, SourceAddress, ServiceId, NetworkId, LinkId, CarrierId);
		}
	}
}
