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

namespace DDUtilityApp.TIBRENDEZVOUS.DATA
{

    public class SendSubject : DataTableBase
    {

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

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

        public bool IsChecked { get; set; } = true;

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

        public SendSubject()
        {
        }

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

        public SendSubject(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)
        {
            SendSubject other = obj as SendSubject;
            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();
        }

    }

}
