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

namespace TellerSystem.Contract.Function
{
    /// <summary>
    /// 证件号码验证
    /// 证件合法性验证
    /// </summary>
    public class IDNumberVerification : TFOutput
    {
        #region Output
        /// <summary>
        /// 证件号码 0620
        /// 15位身份证号转变成18位身份证号
        /// </summary>
        public string ZJHM { get; internal set; }

        /// <summary>
        /// 验证通过标志 0730
        /// 第一位[0]验证是否成功 0.身份证验证失败1.身份证验证成功2.机构代码证验证失败3.机构代码证验证成功
        /// </summary>
        public string YZTGBZ { get; internal set; }


        #endregion

        #region Input
		/// <summary>
        /// 参数清单
        /// </summary>
        public class Input : TFInput
        {
            /// <summary>
            /// 证件类型 0670
            /// 1.身份证8.(组织机构)代码证 
            /// </summary>
            public string ZJLX { get; set; }

            /// <summary>
            /// 证件号码 0620
            /// 主要验证身份证和组织机构代码证 
            /// </summary>
            public string ZJHM { get; set; }


            /// <summary>                 
            /// 定义业务逻辑              
            /// </summary>                
            /// <returns></returns>  
            public override TFOutput Raise()
            {
                //拉取数据                                  
                var output = new IDNumberVerification();
                PageData.TradeAPIs.InitFd(MessageData);
                PageData.TradeAPIs.CommSend(MessageData);
				MessageData.Fd126_5 = MainCode;
                MessageData.Fd16 = "K020";
                MessageData.Fd67 = ZJLX;
                MessageData.Fd62 = ZJHM;

                PageData.TradeAPIs.CallServer(MessageData);
                if (MessageData.Fd12 != "0000")
                {
                    output.IsFailed = true;
                    output.FailureCause = PageData.TradeAPIs.GetError(MessageData);
                }                
                output.ZJHM = (MessageData.Fd62);
                output.YZTGBZ = (MessageData.Fd73);
                //是否当前柜员给自己办理业务
                if (TellerSystem.Library.Ext.TradeExtension.SystemSettingsHelper.Instance.IsTellerCustomer)
                {
                    var idCarNO = TellerSystem.Library.Ext.TradeExtension.LoginAuthentication.Instance.IdCarNO;
                    if (!string.IsNullOrEmpty(idCarNO) && output.ZJHM.Trim() == idCarNO.Trim())
                    {
                        output.IsFailed = true;
                        output.FailureCause = "当前柜员不能为自己办理业务！";
                    }
                }
                return output;
            }
        }
        #endregion
    }
}
