using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Misc;
using System.Net;
using System.Xml;
using System.Xml.Linq;
using System.ComponentModel;

using FLY.Thick.Base.IService;
namespace ThickTcpUiInWindow
{
    /// <summary>
    /// 
    /// </summary>
    public class SysParam : INotifyPropertyChanged, ISaveToXml
    {
        #region 数据文件需要保存的数据项

        IPEndPoint serverep = Misc.StringConverter.ToIPEndPoint("127.0.0.1:20006");
        /// <summary>
        /// 文件同步(服务器地址) IP and Port
        /// </summary>
        public IPEndPoint ServerIPEP
        {
            get
            {
                return serverep;
            }
            set
            {
                if (value == null)
                    return;

                if (!serverep.Equals(value))
                {
                    serverep = new IPEndPoint(value.Address, value.Port);
                    NotifyPropertyChanged("ServerIPEP");
                }
            }
        }


        string _language = "zh-CN";
        /// <summary>
        /// 语言 zh-CN ,en-US
        /// </summary>
        public string Language
        {
            get
            {
                return _language;

            }
            set
            {

                if (!string.IsNullOrEmpty(value))
                {
                    _language = value;
                    NotifyPropertyChanged("Language");
                }
            }
        }


        /// <summary>
        /// 报警音乐路径 
        /// </summary>
        public string WarningTipPath { get; set; }

        /// <summary>
        /// 使用虚拟键盘
        /// </summary>
        public bool HaveOSK { get; set; }


        /// <summary>
        /// 虚拟键盘支持鼠标
        /// </summary>
        public bool HaveOSK_mouse { get; set; }

        /// <summary>
        /// list窗口大小
        /// </summary>
        public int WindowSize { get; set; } = 30;

        /// <summary>
        /// USB 继电器 串口地址
        /// </summary>
        public string LCUS1_PortName { get; set; } = "COM1";

        /// <summary>
        /// 使能USB 继电器
        /// </summary>
        public bool EnableLCUS1 { get; set; }

        #endregion
        /// <summary>
        /// 
        /// </summary>
        public SysParam()
        {
            //Load();
        }

        /// <summary>
        /// 当前加载中，由于加载导致的参数变化，不管它
        /// </summary>
        protected bool ignore = false;
        /// <summary>
        /// 
        /// </summary>
        public void Load() 
        {
            ignore = true;
            Misc.SaveToXmlHepler.Load("csysparam.xml", this);
            ignore = false;
        }
        /// <summary>
        /// 
        /// </summary>
        public void Save() 
        {
            Misc.SaveToXmlHepler.Save("csysparam.xml", this);
        }
        #region INotifyPropertyChanged 成员

        protected void NotifyPropertyChanged(string propertyname)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }
        
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public virtual string[] GetSavePropertyNames()
        {
            return new string[] {
                "ServerIPEP",
                "Language",
                "WarningTipPath",
                "HaveOSK",
                "HaveOSK_mouse",
                "WindowSize",
                "LCUS1_PortName",
                "EnableLCUS1"
            };
        }
    }
}
