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

namespace skyscraper5.DNS.Protocol.ResourceRecords.Records
{
	class NamingAuthorityPointerResourceRecord : BaseResourceRecord
	{
		public NamingAuthorityPointerResourceRecord(IResourceRecord record, byte[] message, int dataOffset)
			: base(record)
		{
			MemoryStream ms = new MemoryStream(Data);
			Order = ms.ReadUInt16BE();
			Preferences = ms.ReadUInt16BE();
			byte flagsLength = ms.ReadUInt8();
			Flags = ms.ReadBytes(flagsLength);
			byte serviceLength = ms.ReadUInt8();
			Service = Encoding.UTF8.GetString(ms.ReadBytes(serviceLength));
			byte regexLength = ms.ReadUInt8();
			Regex = ms.ReadBytes(regexLength);
			Replacement = Domain.FromArray(Data, (int)ms.Position);
		}

		public ushort Order { get; }
		public ushort Preferences { get; }
		public byte[] Flags { get; }
		public string Service { get; }
		public byte[] Regex { get; }
		public Domain Replacement { get; }
	}
}
