using DevExpress.Mvvm.POCO;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Markup;
using VIZ.Framework.Core;
using VIZ.Package.Domain;
using VIZ.Package.Module;

namespace VIZ.TVP.CBA.Module
{
    /// <summary>
    /// 数据访问接口配置
    /// </summary>
    public class HttpUrlConfigViewModel : ViewModelBase
    {
        /// <summary>
        /// 日志
        /// </summary>
        private readonly static ILog log = LogManager.GetLogger(typeof(MediaSettingViewModel));


        private  static AppSetup_InitCBALiteDB appSetup_InitCBALiteDB = AppSetup_InitCBALiteDB.CreateInstance;

     

        /// <summary>
        /// 媒资库配置设置视图模型
        /// </summary>
        public HttpUrlConfigViewModel()
        {
            // 初始化命令
            this.InitCommand();

           // HttpUrlConfigEntity config = AppSetup_InitCBALiteDB.HttpUrlConfigEntity;
        }

        /// <summary>
        /// 初始化命令
        /// </summary>
        private void InitCommand()
        {
            this.LoadedCommand = new VCommand(this.Loaded);

        }


        // =========================================================================
        // Property
        // =========================================================================

        #region 主数据来源

        #region Url -- 地址

        private string url;
        /// <summary>
        /// 地址
        /// </summary>
        public string Url
        {
            get { return url; }
            set { url = value; this.RaisePropertyChanged(nameof(Url)); }
        }

        #endregion


        #region 应用Id
        /// <summary>
        /// 艾果平台应用Id
        /// </summary>
        private string appId;

        public string AppId
        {
            get { return appId; }
            set { appId = value; this.RaisePropertyChanged(nameof(AppId)); }    
        }

        #endregion


        #region 平台Key
        /// <summary>
        /// 艾果应用平台Key
        /// </summary>
        private string appKey;

        public string AppKey
        {
            get { return appKey; }
            set { appKey = value; this.RaisePropertyChanged(nameof(AppKey)); }  
        }

        #endregion

        #endregion


        #region 备份数据来源

        #region Url -- 地址

        private string burl;
        /// <summary>
        /// 地址
        /// </summary>
        public string BUrl
        {
            get { return burl; }
            set { burl = value; this.RaisePropertyChanged(nameof(BUrl)); }
        }

        #endregion


        #region 应用Id
        /// <summary>
        /// 艾果平台应用Id
        /// </summary>
        private string bappId;

        public string BAppId
        {
            get { return bappId; }
            set { bappId = value; this.RaisePropertyChanged(nameof(BAppId)); }
        }

        #endregion


        #region 平台Key
        /// <summary>
        /// 艾果应用平台Key
        /// </summary>
        private string bappKey;

        public string BAppKey
        {
            get { return bappKey; }
            set { bappKey = value; this.RaisePropertyChanged(nameof(BAppKey)); }
        }

        #endregion

        #endregion


        #region 图片地址


        /// <summary>
        /// 球队图片地址
        /// </summary>

        private string teamsLogo;

        public string TeamsLogo
        {
            get { return teamsLogo; }
            set { teamsLogo = value; this.RaisePropertyChanged(nameof(TeamsLogo)); }    
        }


        /// <summary>
        /// 球员图片地址
        /// </summary>
        private string playersLogo;

        public string PlayersLogo
        {
            get { return playersLogo; }
            set { playersLogo = value; this.RaisePropertyChanged(nameof(PlayersLogo)); }
        }

        #endregion 

        // =========================================================================
        // Command
        // =========================================================================

        #region LoadedCommand -- 加载命令

        /// <summary>
        /// 加载命令
        /// </summary>
        public VCommand LoadedCommand { get; set; }

        /// <summary>
        /// 加载
        /// </summary>
        private void Loaded()
        {
      
            this.Url = AppSetup_InitCBALiteDB.HttpUrlConfigEntity.Url;

            this.AppId = AppSetup_InitCBALiteDB.HttpUrlConfigEntity.AppId;

            this.AppKey = AppSetup_InitCBALiteDB.HttpUrlConfigEntity.AppKey;


            this.BUrl = AppSetup_InitCBALiteDB.HttpUrlConfigEntity.BUrl;

            this.BAppId = AppSetup_InitCBALiteDB.HttpUrlConfigEntity.BAppId;

            this.BAppKey = AppSetup_InitCBALiteDB.HttpUrlConfigEntity.BAppKey;

            this.TeamsLogo = AppSetup_InitCBALiteDB.HttpUrlConfigEntity.TeamsLogo;

            this.PlayersLogo=AppSetup_InitCBALiteDB.HttpUrlConfigEntity.PlayersLogo;



        }

        #endregion

        // =========================================================================
        // Public Function
        // =========================================================================

        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            HttpUrlConfigEntity config = AppSetup_InitCBALiteDB.HttpUrlConfigEntity;
            config.Url = this.Url;
            config.AppId = this.AppId;
            config.AppKey = this.AppKey;

            config.BUrl = this.BUrl;
            config.BAppId = this.BAppId;
            config.BAppKey = this.BAppKey;

            config.TeamsLogo = this.TeamsLogo;
            config.PlayersLogo = this.PlayersLogo;

            AppSetup_InitCBALiteDB.cBALocalDbContext.HttpUrlConfig.Upsert(config);




        }
    }
}
