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

namespace skyscraper5.Dvb.SystemSoftwareUpdate.Model
{
    public class UpdateNotificationGroup
    {
        public byte ActionType { get; }
        public byte OuiHash { get; }
        public string Oui { get; }
		[JsonIgnore] public int OuiAsInt { get; private set; }
		public byte ProcessingOrder { get; }

        //from descriptor 0x03 ssu location descriptor
        public ushort? DataBroadcastId { get; set; }
        public ushort? AssociationTag { get; set; }
        public byte[] PrivateData { get; set; }

        //from descriptor 0x02 update descriptor
        public int? UpdateFlag { get; set; }
        public int? UpdateMethod { get; set; }
        public int? UpdatePriority { get; set; }


        protected UpdateNotificationGroup()
        {

        }

        protected UpdateNotificationGroup(UpdateNotificationGroup copyFrom)
        {
            this.ActionType = copyFrom.ActionType;
            this.OuiHash = copyFrom.OuiHash;
            this.Oui = copyFrom.Oui;
            this.ProcessingOrder = copyFrom.ProcessingOrder;
            this.DataBroadcastId = copyFrom.DataBroadcastId;
            this.AssociationTag = copyFrom.AssociationTag;
            this.PrivateData = copyFrom.PrivateData;
            this.UpdateFlag = copyFrom.UpdateFlag;
            this.UpdateMethod = copyFrom.UpdateMethod;
            this.UpdatePriority = copyFrom.UpdatePriority;
        }

        public UpdateNotificationGroup(byte actionType, byte ouiHash, byte[] oui, byte processingOrder)
        {
            ActionType = actionType;
            OuiHash = ouiHash;
            Oui = Convert.ToHexString(oui);
            OuiAsInt = oui[2] << 16 | oui[1] << 8 | oui[0];
            ProcessingOrder = processingOrder;
        }

        public override string ToString()
        {
            return $"{nameof(Oui)}: {Oui}";
        }
    }
}
