using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper8.Skyscraper.Security.AccessControl
{
	internal class PowerVuKeyGroup
	{
		public uint Coordinate { get; }

		public PowerVuKeyGroup(uint coordinate, ushort groupId)
		{
			Coordinate = coordinate;
			GroupId = groupId;
		}

		public ushort GroupId { get; set; }

		public bool SetHint(uint coordinate, uint keyType, byte[] key)
		{
			if ((coordinate & 0x0000ffff) == 0x0000ffff)
			{
				if (keyType == 0)
				{
					EcmA = key;
					return true;
				}
				else if (keyType == 1)
				{
					EcmB = key;
					return true;
				}
				else
				{
					return false;
				}
			}
			if (_keys == null)
				_keys = new List<Tuple<uint, uint, byte[]>>();

			_keys.Add(new Tuple<uint, uint, byte[]>(coordinate, keyType, key));
			return true;
		}

		public byte[] EcmB { get; set; }

		public byte[] EcmA { get; set; }

		private List<Tuple<uint, uint, byte[]>> _keys;
		public IReadOnlyList<Tuple<uint, uint, byte[]>> Keys;
	}
}
