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

namespace skyscraper5.src.InteractionChannel.Model
{
	public class Spt : Validatable
	{
		public Spt(MemoryStream ms)
		{
			byte satelliteLoopCount = ms.ReadUInt8(); satelliteLoopCount++;
			Satellites = new Satellite[satelliteLoopCount];
			for (int i = 0; i < satelliteLoopCount; i++)
			{
				Satellites[i] = new Satellite();
				Satellites[i].Id = ms.ReadUInt8();
				Satellites[i].X = ms.ReadUInt32BE();
				Satellites[i].Y = ms.ReadUInt32BE();
				Satellites[i].Z = ms.ReadUInt32BE();
			}
			uint crc32 = ms.ReadUInt32BE();
			Valid = true;
		}

		public Satellite[] Satellites { get; }
		public class Satellite
		{
			public Satellite()
			{

			}

			public Satellite(byte id, uint x, uint y, uint z)
			{
				Id = id;
				X = x;
				Y = y;
				Z = z;
			}

			public Satellite(Satellite copy)
			{
				Id = copy.Id;
				X = copy.X;
				Y = copy.Y;
				Z = copy.Z;
			}

			public byte Id { get; internal set; }
			public uint X { get; internal set; }
			public uint Y { get; internal set; }
			public uint Z { get; internal set; }

			protected bool Equals(Satellite other)
			{
				return Id == other.Id;
			}

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

			public override int GetHashCode()
			{
				return Id.GetHashCode();
			}
		}
	}
}
