using System;
using System.ComponentModel;
using System.Text;
using System.Xml;
using JWH;
using JWH.DATA;

namespace DDUtilityApp.TIBRENDEZVOUS.DATA
{

    public class Network : DataTableBase
    {

        public string Name { get; set; } = string.Empty;

        public string Value { get; set; } = string.Empty;

        [ReadOnly(true)]
        public string Description { get { return $"[{this.Name}] {this.Value}"; } }

        public Network()
        {
        }

        public Network(string name, string value)
        {
            this.Name = name;
            this.Value = value;
        }

        public Network(XmlNode node)
        {
            try
            {
                node.PropertiesCopyAttribute(this);
                this.Value = node.InnerText;
            }
            catch (Exception ex)
            {
                XLogger.Instance.Fatal(ex);
            }
        }

        public string ToXmlString(string indent = "")
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine($"{indent}<{this.GetType().Name}>{this.Value}</{this.GetType().Name}>");

                return sb.ToString();
            }
            catch (Exception ex)
            {
                XLogger.Instance.Fatal(ex);
                throw ex;
            }
        }

        public override string ToString()
        {
            return $"[{this.Name}] {this.Value}";
        }

        public override bool Equals(object obj)
        {
            Network other = obj as Network;
            if (other == null) return false;

            if (!this.Name.Equals(other.Name)) return false;
            if (!this.Value.Equals(other.Value)) return false;

            return true;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

    }

}
