using System;
using System.Globalization;
using System.Xml.Serialization;

namespace Hncore.Pass.PaymentCenter.WeiFuTong.Notify
{
    [XmlRoot("xml", Namespace = "")]
    public class NotifyResponse : WeiFuTongResponseBase
    {
        /// <summary>
        /// 用户在服务商 appid 下的唯一标识
        /// </summary>
        [XmlElement("openid")]
        public string OpenId { get; set; }

        /// <summary>
        /// 交易类型
        /// </summary>
        [XmlElement("trade_type")]
        public string TradeType { get; set; }

        /// <summary>
        /// 用户是否关注服务商公众账号，Y-关注，N-未关注
        /// </summary>
        [XmlElement("is_subscribe")]
        public string IsSubscribe { get; set; }

        /// <summary>
        /// 支付结果：0—成功；其它—失败
        /// </summary>
        [XmlElement("pay_result")] 
        public int PayResult { get; set; }
        
        /// <summary>
        /// 支付结果信息，支付成功时为空
        /// </summary>
        [XmlElement("pay_info")]
        public string PayInfo { get; set; }
        
        /// <summary>
        /// 平台交易号
        /// </summary>
        [XmlElement("transaction_id")]
        public string TransactionId { get; set; }

        /// <summary>
        /// 第三方订单号
        /// </summary>
        [XmlElement("out_transaction_id")]
        public string OutTransactionId { get; set; }

        /// <summary>
        /// 第三方商户单号，可在支持的商户扫码退款
        /// </summary>
        [XmlElement("third_order_no")]
        public string ThirdOrderNo { get; set; }
        
        /// <summary>
        /// 用户是否关注子公众账号，Y-关注，N-未关注，仅在公众账号类型支付有效
        /// </summary>
        [XmlElement("sub_is_subscribe")]
        public string SubIsSubscribe { get; set; }
        
        /// <summary>
        /// 子商户appid
        /// </summary>
        [XmlElement("sub_appid")]
        public string SubAppId { get; set; }
        
        /// <summary>
        /// 用户在子商户appid下的唯一标识
        /// </summary>
        [XmlElement("sub_openid")]
        public string SubOpenId { get; set; }
        
        /// <summary>
        /// 商户系统内部的定单号，32个字符内、可包含字母
        /// </summary>
        [XmlElement("out_trade_no")]
        public string OutTradeNo { get; set; }
        
        /// <summary>
        /// 总金额，以分为单位，不允许包含任何字、符号
        /// </summary>
        [XmlElement("total_fee")]
        public int TotalFee { get; set; }

        /// <summary>
        /// 现金支付金额【微信】 
        /// </summary>
        [XmlElement("cash_fee")]
        public int CashFee { get; set; }
        
        /// <summary>
        /// 现金券金额【微信】
        /// </summary>
        [XmlElement("coupon_fee")]
        public string CouponFee { get; set; }
        
        /// <summary>
        /// 货币类型，符合 ISO 4217 标准的三位字母代码，默认人民币：CNY
        /// </summary>
        [XmlElement("fee_type")]
        public string FeeType { get; set; }
        
        /// <summary>
        /// 商家数据包，原样返回
        /// </summary>
        [XmlElement("attach")]
        public string Attach { get; set; }
        
        /// <summary>
        /// 付款银行
        /// </summary>
        [XmlElement("bank_type")]
        public string BankType { get; set; }
        
        /// <summary>
        /// 银行订单号，若为微信支付则为空
        /// </summary>
        [XmlElement("bank_billno")]
        public string BankBillno { get; set; }
        
        /// <summary>
        /// 支付完成时间，格式为yyyyMMddHHmmss，如2009年12月27日9点10分10秒表示为20091227091010。时区为GMT+8 beijing。该时间取自平台服务器
        /// </summary>
        [XmlElement("time_end")]
        public string TimeEnd { get; set; }

        /// <summary>
        /// 获取支付成功时间
        /// </summary>
        /// <returns></returns>
        public DateTime GetPaySuccessTime()
        {
            DateTime.TryParseExact(TimeEnd, "yyyyMMddHHmmss", null, DateTimeStyles.None, out var paySuccessTime);

            return paySuccessTime;
        }
    }
}