using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Com.FirmLib;
using FWindSoft.Data;
using SAGA.DotNetUtils.Extend;
using SAGA.DotNetUtils.Utilities;

namespace FirmHttpDao
{
    public class BllHttpSetting 
    {
        public static readonly BllHttpSetting Instance =new BllHttpSetting();
        public BllHttpSetting()
        {
            Default = new FileUrlValidate() { SystemId = "dev", Secret = "123" };
        }

        public string DeleteKey()
        {
            return "/delete";
        }

        public string InsertKey()
        {
            return "/create";
        }

        public string SearchKey()
        {
            return "/query";
        }

        public string UpdateKey()
        {
            return "/update";
        }
        public string EndUri
        {
            //get { return "http://101.201.234.108:28888/venders"; }
            get { return InnerSetting.Current.VenderAddress; }
        }
        public string DpUri
        {
            //get { return "http://101.201.234.108:28888/venders-dp"; }
            get { return InnerSetting.Current.DependencyAddress; }
        }
        public string EquipmentUri
        {
            //get { return "http://101.201.234.108:28888/data-platform-3/"; }
            get { return InnerSetting.Current.EquipmentFamilyAddress; }
        }

        public string FileUri
        {   //get { return "http://101.201.234.108:28888/data-platform-3/"; }
            get { return InnerSetting.Current.FileAddress; }
        }
        //public string SaasUri
        //{   //get { return "http://101.201.234.108:28888/data-platform-3/"; }
        //    get { return InnerSetting.Current.SaasAddress; }
        //}
        public string H5Url
        {
            get { return InnerSetting.Current.H5Address; }
        }
        public FileUrlValidate Default { get;private set; }
    }

    public class InnerSetting
    {
        #region 静态操作
        public static void SaveConfigureInfo(string key, string value)
        {
            IniOperator.Instance(ConfigPath).SetData("Configure", key, value);
        }
        public static string GetConfigureInfo(string key)
        {
            return IniOperator.Instance(ConfigPath).GetData("Configure", key);
        }
        #endregion
        private static string ConfigPath { get; set; }
        static InnerSetting()
        {
            string path=Path.Combine(Directory.GetParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).FullName,
                "MBIResource", "Config", ConfigurationUtil.Default.GetSettingValue("HttpSetting") ?? "HttpSetting.ini");
            //string path =Path.Combine(Directory.GetParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).FullName, @"MBIResource\Config\HttpSetting.ini");
            ConfigPath = path;
            //XmlFileConfig<InnerSetting> config = new XmlFileConfig<InnerSetting>(path, "");
            //config.Load(); 
            //Current = config.RefObject;
            Current = new InnerSetting();
            Current.VenderAddress = GetConfigureInfo(nameof(Current.VenderAddress));
            Current.DependencyAddress = GetConfigureInfo(nameof(Current.DependencyAddress));
            Current.EquipmentFamilyAddress = GetConfigureInfo(nameof(Current.EquipmentFamilyAddress));
            Current.FileAddress = GetConfigureInfo(nameof(Current.FileAddress));
            Current.H5Address = GetConfigureInfo(nameof(Current.H5Address));
        }
        public InnerSetting()
        {
            VenderAddress = @"http://127.0.0.1";
            DependencyAddress = @"http://127.0.0.1";
            EquipmentFamilyAddress = @"http://127.0.0.1";
            FileAddress= @"http://127.0.0.1";
            //SaasAddress = @"http://127.0.0.1";
        }

       
        public static InnerSetting Current { get; private set; }
        /// <summary>
        ///  基地址
        /// </summary>
        public string VenderAddress { get; set; }
        /// <summary>
        /// 辅助地址
        /// </summary>
        public string DependencyAddress { get; set; }
        /// <summary>
        /// 辅助地址
        /// </summary>
        public string EquipmentFamilyAddress { get; set; }
        /// <summary>
        /// 文件服务器地址
        /// </summary>
        public string FileAddress { get; set; }
      

        /// <summary>
        /// H5网页展示
        /// </summary>
        public string H5Address { get; set; }

        public static void Save()
        {
            //XmlFileConfig<InnerSetting> config = new XmlFileConfig<InnerSetting>(@"c:\HttpSetting.xml", "");
            //config.RefObject = new InnerSetting();
            //config.Save();
        }
    }
}
