using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using TellerSystem.ServiceProxy.Ext.ServiceHelper;

namespace TellerSystem.Contract.Function
{
    /// <summary>
    /// 按揭当前与欠款查询
    /// 按揭当前与欠款查询
    /// </summary>
    public class QueryMortgageDebt : TFOutput
    {
        #region Output
        /// <summary>
        /// 欠款本金 0390
        /// 
        /// </summary>
        public string QKBJ { get; internal set; }

        /// <summary>
        /// 欠款利息 0400
        /// 
        /// </summary>
        public string QKLL { get; internal set; }

        /// <summary>
        /// 欠款罚息 0410
        /// 
        /// </summary>
        public string QKFX { get; internal set; }

        /// <summary>
        /// 本期本金 0420
        /// 
        /// </summary>
        public string BQBJ { get; internal set; }

        /// <summary>
        /// 本期利息 0430
        /// 
        /// </summary>
        public string BQLX { get; internal set; }

        /// <summary>
        /// 按揭列表
        /// 期次|欠本金|欠利息|欠罚息|还本金|还利息|还罚息|应还日期|
        /// </summary>
        public string AJLB { get; internal set; }

        /// <summary>
        /// 按揭列表
        /// 期次|欠本金|欠利息|欠罚息|还本金|还利息|还罚息|应还日期|
        /// </summary>
        public List<E_AJLB> AJLBData { get; internal set; }

        /// <summary>
        /// 按揭列表
        /// 期次|欠本金|欠利息|欠罚息|还本金|还利息|还罚息|应还日期|
        /// </summary>
        public class E_AJLB
        {
            /// <summary>
            /// 期次
            /// </summary>
            public string QC { get; set; }

            /// <summary>
            /// 欠本金
            /// </summary>
            public string QBJ { get; set; }

            /// <summary>
            /// 欠利息
            /// </summary>
            public string QLX { get; set; }

            /// <summary>
            /// 欠罚息
            /// </summary>
            public string QFX { get; set; }

            /// <summary>
            /// 还本金
            /// </summary>
            public string HBJ { get; set; }

            /// <summary>
            /// 还利息
            /// </summary>
            public string HLX { get; set; }

            /// <summary>
            /// 还罚息
            /// </summary>
            public string HFX { get; set; }

            /// <summary>
            /// 应还日期
            /// </summary>
            public string YHRQ { get; set; }

        }
        /// <summary>
        /// 是否按揭类型 0670
        /// Y:是  N:否
        /// </summary>
        public string SFAJLX { get; internal set; }
        
        /// <summary>
        /// 本期期次 109F 天骄
        /// </summary>
        public string BQQC { get; set; }

        /// <summary>
        /// 户名 0250
        /// 
        /// </summary>
        public string HM { get; internal set; }

        /// <summary>
        /// 借据号 0310
        /// 
        /// </summary>
        public string JJH { get; internal set; }
        /// <summary>
        /// 表内欠息 1085
        /// 
        /// </summary>
        public string BNQX { get; internal set; }

        /// <summary>
        /// 表外欠息 1086
        /// 
        /// </summary>
        public string BWQX { get; internal set; }
        /// <summary>
        /// 复利欠息 1087
        /// 
        /// </summary>
        public string FLQX { get; internal set; }
        /// <summary>
        /// 贷款现余额 1084
        /// 
        /// </summary>
        public string DKXYE { get; internal set; }
        /// <summary>
        /// 未结本金罚息 1088
        /// 
        /// </summary>
        public string WJBJLX { get; internal set; }

        /// <summary>
        /// 未结复利利息 1089
        /// 
        /// </summary>
        public string WJFLLX { get; internal set; }
        #endregion

        #region Input
		/// <summary>
        /// 参数清单
        /// </summary>
        public class Input : TFInput
        {
            /// <summary>
            /// 账号 0380
            ///  
            /// </summary>
            public string ZH { get; set; }

            /// <summary>
            /// 开始期数 0500
            ///  
            /// </summary>
            public string KSQS { get; set; }

            /// <summary>
            /// 结束期数 0510
            ///  
            /// </summary>
            public string JSQS { get; set; }

            /// <summary>
            /// 结息标志 0650
            /// </summary>
            public string JXBZ { get; set; }

            /// <summary>                 
            /// 定义业务逻辑              
            /// </summary>                
            /// <returns></returns>  
            public override TFOutput Raise()
            {
                //拉取数据                                  
                var output = new QueryMortgageDebt();
                PageData.TradeAPIs.InitFd(MessageData);
                PageData.TradeAPIs.CommSend(MessageData);
				MessageData.Fd126_5 = MainCode;
                MessageData.Fd16 = "K044";
                MessageData.Fd38 = ZH;
                MessageData.Fd50 = KSQS;
                MessageData.Fd51 = JSQS;
                MessageData.Fd65 = JXBZ;
      
                PageData.TradeAPIs.CallServer(MessageData);
                if (MessageData.Fd12 != "0000")
                {
                    output.IsFailed = true;
                    output.FailureCause = PageData.TradeAPIs.GetError(MessageData);
                }                
                output.QKBJ = (MessageData.Fd39);
                output.QKLL = (MessageData.Fd40);
                output.QKFX = (MessageData.Fd41);
                output.BQBJ = (MessageData.Fd42);
                output.BQLX = (MessageData.Fd43);

                output.HM = (MessageData.Fd25);
                output.JJH = (MessageData.Fd31);
                output.DKXYE = (MessageData.Fd108_4);
                output.BNQX = (MessageData.Fd108_5);
                output.BWQX = (MessageData.Fd108_6);
                output.FLQX = (MessageData.Fd108_7);
                output.WJBJLX = (MessageData.Fd108_8);
                output.WJFLLX = (MessageData.Fd108_9);

                output.AJLBData = AnilyzeFileData<E_AJLB>(MessageData.FileData,
                                            "期次|欠本金|欠利息|欠罚息|还本金|还利息|还罚息|应还日期|",
                                            x =>
                                            {
                                                return new E_AJLB
                                                {
                                                    QC = x["期次"],
                                                    QBJ = x["欠本金"],
                                                    QLX = x["欠利息"],
                                                    QFX = x["欠罚息"],
                                                    HBJ = x["还本金"],
                                                    HLX = x["还利息"],
                                                    HFX = x["还罚息"],
                                                    YHRQ = x["应还日期"]
                                                };
                                            });
                output.AJLB = MessageData.FileData;
                output.SFAJLX = (MessageData.Fd67);

                string FLAG = TradeManagerHandle.TT_SYSCONFIG_GetConfigValueByConfigID("2ea3a7e6cfa04f89a335bf1e363295de");
                if (FLAG == "V21" || FLAG == "V22")
                {
                    output.BQQC = MessageData.Fd109_F;
                }

                return output;
            }
        }
        #endregion
    }
}
