using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// 网站配置
/// </summary>
 
namespace Basic.BLL
{
    public class siteconfig
    {
        private readonly Basic.DAL.siteconfig dal = new Basic.DAL.siteconfig();

        /// <summary>
        ///  读取配置文件
        /// </summary>
        public Basic.Model.siteconfig loadConfig(string configFilePath)
        {
            Basic.Model.siteconfig model = CacheHelper.Get<Basic.Model.siteconfig>(Keys.CACHE_SITE_CONFIG);
            if (model == null)
            {
                CacheHelper.Insert(Keys.CACHE_SITE_CONFIG, dal.loadConfig(configFilePath), configFilePath);
                model = CacheHelper.Get<Basic.Model.siteconfig>(Keys.CACHE_SITE_CONFIG);
            }
            return model;
        }

        /// <summary>
        /// 读取客户端站点配置信息
        /// </summary>
        public Basic.Model.siteconfig loadConfig(string configFilePath, bool isClient)
        {
            Basic.Model.siteconfig model = CacheHelper.Get<Basic.Model.siteconfig>(Keys.CACHE_SITE_CONFIG_CLIENT);
            if (model == null)
            {
                model = dal.loadConfig(configFilePath);
                model.templateskin = model.webpath + "templates/" + model.templateskin;
                CacheHelper.Insert(Keys.CACHE_SITE_CONFIG_CLIENT, model, configFilePath);
            }
            return model;
        }

        public static string getConfig(string valueName)
        {

            Basic.BLL.siteconfig bll = new Basic.BLL.siteconfig();
            Basic.Model.siteconfig model = bll.loadConfig(Basic.Tools.Utils.GetXmlMapPath(Basic.Keys.FILE_SITE_XML_CONFING));

            string strResult = "";
            if (model != null)
            {
               
                switch (valueName)
                {
                    case "appid":
                        strResult = model.Wechat_appid;
                        break;
                    case "appsecret":
                        strResult = model.Wechat_appsecret;
                        break;
                    case "mchid":
                        strResult = model.Wechat_hchid;
                        break;
                    case "key":
                        strResult = model.Wechat_key;
                        break;
                }
            }
            return strResult;
        }

        /// <summary>
        ///  保存配置文件
        /// </summary>
        public Basic.Model.siteconfig saveConifg(Basic.Model.siteconfig model, string configFilePath)
        {
            return dal.saveConifg(model, configFilePath);
        }
    }
}