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

namespace skyscraper5.DNS.Protocol.ResourceRecords.Records
{
	public class MailExchangeResourceRecord : BaseResourceRecord
	{
		private const int PREFERENCE_SIZE = 2;

		public MailExchangeResourceRecord(IResourceRecord record, byte[] message, int dataOffset)
			: base(record)
		{
			byte[] preference = new byte[MailExchangeResourceRecord.PREFERENCE_SIZE];
			Array.Copy(message, dataOffset, preference, 0, preference.Length);

			if (BitConverter.IsLittleEndian)
			{
				Array.Reverse(preference);
			}

			dataOffset += MailExchangeResourceRecord.PREFERENCE_SIZE;

			Preference = BitConverter.ToUInt16(preference, 0);
			ExchangeDomainName = Domain.FromArray(message, dataOffset);
		}

		public int Preference { get; }
		public Domain ExchangeDomainName { get; }
	}
}
