using skyscraper5.Dvb.Descriptors;
using skyscraper8.Ses.Descriptors;
using skyscraper8.Skyscraper.Scraper.Storage.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper8.Ses
{
	public class SgtService
	{
		public SgtService(ushort serviceListId)
		{
			ServiceListId = serviceListId;
		}

		public ushort ServiceListId { get; }

		public ushort ServiceId { get; internal set; }
		public ushort TransportStreamId { get; internal set; }
		public ushort OriginalNetworkId { get; internal set; }
		public int Lcn { get; internal set; }
		public bool VisibleServiceFlag { get; internal set; }
		public bool NewServiceFlag { get; internal set; }
		public ushort GenreCode { get; internal set; }

		//In SGT this is mandatory and defaults to 0x01
		public uint PrivateDataSpecifier { get; internal set; }
		public ushort[] CaSystemIds { get; internal set; }
		public ServiceDescriptor ServiceDescriptor { get; internal set; }
		public List<uint> VirtualServiceIds { get; internal set; }
		public string? BouquetList { get; internal set; }

		public override bool Equals(object? obj)
		{
			return obj is SgtService service &&
				   ServiceListId == service.ServiceListId &&
				   ServiceId == service.ServiceId &&
				   TransportStreamId == service.TransportStreamId &&
				   OriginalNetworkId == service.OriginalNetworkId;
		}

		public override int GetHashCode()
		{
			return HashCode.Combine(ServiceListId, ServiceId, TransportStreamId, OriginalNetworkId);
		}

		public string GetName()
		{
			if (ServiceDescriptor == null)
				return "???";

			return ServiceDescriptor.ServiceName;
		}

		public DatabaseKeySgtService GetDatabaseKey()
		{
			return new DatabaseKeySgtService(ServiceListId, ServiceId, TransportStreamId, OriginalNetworkId);
		}
	}
}
