using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TellerSystem.Communication;

namespace TellerSystem.Contract.ContractBase
{
    /// <summary>
    /// 入口基类，包括Message和PageBase
    /// </summary>
    public class EntryBase : ITradeHelper
    {
        #region 数据属性
        public Message MessageData { get; private set; }
        public PageBase PageData { get; private set; }
        #endregion

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="page"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool LoadData(PageBase page, Message message)
        {
            var flag = true;
            //检测参数变化
            if (page != null && page == PageData)
            {
                if (message == MessageData || (message.FileData == MessageData.FileData && message.GetAllFds().Except(MessageData.GetAllFds()).Count() == 0))//KeyValuePair是结构体，会对比下辖所有值
                    flag = false;//参数与历史登记一致，未作修改
            }
            PageData = page;
            MessageData = message;
            return OnLoadData(flag);
        }

        /// <summary>
        /// 加载数据时触发
        /// </summary>
        /// <param name="changed">标识数据是否发生改变</param>
        /// <returns></returns>
        protected virtual bool OnLoadData(bool changed)
        {
            return true;
        }

        #region ITradeHelper
        public TradeBusHelper TradeBus
        {
            get { return PageData.TradeBus; }
        }

        public TradeInfoHelper TradeInfo
        {
            get { return PageData.TradeInfo; }
        }

        public TradeAPIsHelper TradeAPIs
        {
            get { return PageData.TradeAPIs; }
        }

        public TradeResourcesHelper TradeResources
        {
            get { return PageData.TradeResources; }
        }
        #endregion
    }
}
