using Newtonsoft.Json;
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
{
	internal class DelegationSignerResourceRecord : BaseResourceRecord, SimpleDnsRecord
	{
		public DelegationSignerResourceRecord(IResourceRecord record, byte[] message, int dataOffset) : base(record)
		{
			MemoryStream ms = new MemoryStream(Data, false);
			KeyId = ms.ReadUInt16BE();
			Algorithm = (AlgorithmEnum)ms.ReadUInt8();
			DigestType = (DigestEnum)ms.ReadUInt8();
			Digest = ms.ReadBytes(ms.GetAvailableBytes());

		}

		public ushort KeyId { get; }
		public AlgorithmEnum Algorithm { get; }
		public DigestEnum DigestType { get; }
		public byte[] Digest { get; }

		public string GetDataAsString()
		{
			dynamic child = new
			{
				KeyId = KeyId,
				Algorithm = Algorithm,
				DigestType = DigestType,
				Digest = Digest,
			};
			string result = JsonConvert.SerializeObject(child);
			return result;
		}
	}

	public enum DigestEnum
	{
		SHA1 = 1,
		SHA256 = 2,
		GOST_R_34_11_94 = 3,
		SHA384 = 4
	}
}
