using Newtonsoft.Json;

using SKIT.FlurlHttpClient.Wechat.TenpayV3;
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
namespace CloudGaming.AppConfigModel
{

    /// <summary>
    /// 
    /// </summary>
    public class PaymentModel
    {
        /// <summary>
        /// 微信支付数据
        /// </summary>
        public WeChatConfig? WeChatConfig { get; set; }

        /// <summary>
        /// 支付宝支付数据
        /// </summary>
        public AliPayConfig? AlipayConfig { get; set; }

        /// <summary>
        /// 
        /// </summary>
        private WechatTenpayClient _wxClient;
        /// <summary>
        /// 微信支付客户端
        /// </summary>
        [JsonIgnore]
        public WechatTenpayClient? WxClientContext
        {
            get
            {
                if (_wxClient == null)
                {
                    if (WeChatConfig == null)
                    {
                        return null;
                    }
                    var manager = new InMemoryCertificateManager();
                    /* 仅列出必须配置项。也包含一些诸如超时时间、UserAgent 等的配置项 */
                    var wechatTenpayClientOptions = new WechatTenpayClientOptions()
                    {

                        MerchantId = WeChatConfig.MchId,
                        MerchantV3Secret = WeChatConfig.Key,
                        MerchantCertificateSerialNumber = WeChatConfig.MerchantCertificateSerialNumber,
                        MerchantCertificatePrivateKey = WeChatConfig.MerchantCertificatePrivateKey,
                        PlatformCertificateManager = manager
                    };
                    _wxClient = new WechatTenpayClient(wechatTenpayClientOptions);
                }
                return _wxClient;
            }
        }

        private Alipay.EasySDK.Kernel.Context _aliPayContext;
        /// <summary>
        /// 支付宝支付
        /// </summary>
        [JsonIgnore]
        public Alipay.EasySDK.Kernel.Context AliPayContext
        {
            get
            {
                if (_aliPayContext == null)
                {
                    if (AlipayConfig != null)
                    {
                        _aliPayContext = new Alipay.EasySDK.Kernel.Context(AlipayConfig, "alipay-easysdk-net-2.1.0");
                    }
                }
                return _aliPayContext;
            }
        }
    }
}
