using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace TellerSystem.Contract.Function
{
    /// <summary>
    /// 客户查询
    /// 根据证件类型证件号查询已开立的客户
    /// </summary>
    public class QueryCustomer : TFOutput
    {
        #region Output
        /// <summary>
        /// 文件
        /// 文件格式：客户号|客户名称|证件号码
        /// </summary>
        public string Sts { get; internal set; }
        /// <summary>
        /// 状态为cif_id_code_rel.sts char[2]0730域
        /// 第一位标志位：该证件号是否已经做过合并客户号交易 1做过 0没做过
        /// </summary>
        public string WJ { get; internal set; }

        /// <summary>
        /// 文件
        /// 文件格式：客户号|客户名称|证件号码
        /// </summary>
        public List<E_WJ> WJData { get; internal set; }
       
        /// <summary>
        /// 文件
        /// 文件格式：客户号|客户名称|证件号码
        /// </summary>
        public class E_WJ
        {
            /// <summary>
            /// 客户号
            /// </summary>
            public string KHH { get; set; }

            /// <summary>
            /// 客户名称
            /// </summary>
            public string KHMC { get; set; }

            /// <summary>
            /// 证件号码
            /// </summary>
            public string ZJHM { get; set; }

        }

        #endregion

        #region Input
        /// <summary>
        /// 参数清单
        /// </summary>
        public class Input : TFInput
        {
            /// <summary>
            /// 证件号码 0620
            /// (null) 
            /// </summary>
            public string ZJHM { get; set; }

            /// <summary>
            /// 客户类型 0670
            /// (null) 
            /// </summary>
            public string KHLX { get; set; }

            /// <summary>
            /// 证件类型 0680
            /// (null) 
            /// </summary>
            public string ZJLX { get; set; }

            /// <summary>
            /// 身份证15或18匹配查询标志 0720
            /// 1.匹配2.不匹配(建立客户ID.对私开户需要传值) 
            /// </summary>
            public string SFZBZ { get; set; }

            /// <summary>
            /// 客户号
            /// </summary>
            public string KHH { get; set; }

            /// <summary>
            /// 客户名称
            /// </summary>
            public string KHMC { get; set; }

            /// <summary>
            /// 手机号码
            /// </summary>
            public string SJHM { get; set; }


            /// <summary>                 
            /// 定义业务逻辑              
            /// </summary>                
            /// <returns></returns>  
            public override TFOutput Raise()
            {
                //拉取数据                                  
                var output = new QueryCustomer();
                PageData.TradeAPIs.InitFd(MessageData);
                PageData.TradeAPIs.CommSend(MessageData);
                MessageData.Fd126_5 = MainCode;
                MessageData.Fd16 = "K022";
                MessageData.Fd62 = ZJHM;
                MessageData.Fd67 = KHLX;
                MessageData.Fd68 = ZJLX;
                MessageData.Fd72 = SFZBZ;
                MessageData.Fd28 = KHH;
                MessageData.Fd102_H = KHMC;

                MessageData.Fd88 = SJHM;

                PageData.TradeAPIs.CallServer(MessageData);
                if (MessageData.Fd12 != "0000")
                {
                    output.IsFailed = true;
                    output.FailureCause = PageData.TradeAPIs.GetError(MessageData);
                }
                output.WJData = AnilyzeFileData<E_WJ>(MessageData.FileData,
                                            "客户号|客户名称|证件号码",
                                            x =>
                                            {
                                                return new E_WJ
                                                {
                                                    KHH = x["客户号"],
                                                    KHMC = x["客户名称"],
                                                    ZJHM = x["证件号码"]
                                                };
                                            });
                output.WJ = MessageData.FileData;
                output.Sts = MessageData.Fd73;
                return output;
            }
        }
        #endregion
    }
}
