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

namespace IpRangeToConfigConverter.Models
{
    public class cSubnetXmlValues
    {
        [XmlArray("Computation-Subnet")]
        [XmlArrayItem("Computation-Subnet-Entry")]
        public List<cComputationSubnetEntry> SubnetEntries { get; set; } = new List<cComputationSubnetEntry>();

        [XmlArray("Computation-Enumeration")]
        [XmlArrayItem("Computation-Enumeration-Entry")]
        public List<cComputationEnumerationEntry> SubnetEnumerations { get; set; } = new List<cComputationEnumerationEntry>();

        public class cComputationSubnetEntry
        {
            [XmlAttribute]
            public string Subnet { get; set; }

            [XmlAttribute]
            public string UpperSubnet { get; set; }


            [XmlIgnore]
            public int? SubnetBits { get; set; }

            [XmlAttribute("SubnetBits")]
            public string SubnetBitsAsText
            {
                get { return (SubnetBits.HasValue) ? SubnetBits.ToString() : null; }
                set { SubnetBits = !string.IsNullOrEmpty(value) ? int.Parse(value) : default(int?); }
            }

            [XmlAttribute]
            public string Value { get; set; }

            public cComputationSubnetEntry()
            {

            }

            public cComputationSubnetEntry(cSubnetDefinition subnetDefinition)
            {
                Subnet = subnetDefinition.Subnet;
                UpperSubnet = subnetDefinition.UpperSubnet;
                SubnetBits = subnetDefinition.SubnetBits;
                Value = subnetDefinition.Value;
            }
        }

        public class cComputationEnumerationEntry
        {
            [XmlAttribute]
            public string Value { get; set; }

            [XmlText]
            public string EnumerationValue { get; set; }

            public cComputationEnumerationEntry()
            {

            }

            public cComputationEnumerationEntry(cSubnetDefinition subnetDefinition)
            {
                Value = subnetDefinition.Value;
                EnumerationValue = subnetDefinition.ConnectionSpeed;
            }
        }

    }
}
