using Aop.Api;
using BaseModel.Models;
using System.Collections.Generic;

namespace WayneCloud.PaymentProcessors.Alipay.FromSDK
{
    /// <summary>
    /// F2FBiz 的摘要说明
    /// </summary>
    public class F2FBiz
    {
        private F2FBiz() { }

        private static volatile IAopClient client;

        private static volatile Dictionary<AliPayConfig, IAopClient> clients = new Dictionary<AliPayConfig, IAopClient>();
        public static IAopClient Clients(AliPayConfig config)
        {
            if (config != null)
            {
                if (client == null)
                {
                    client = new DefaultAopClient(config.serverUrl,
                                                         config.appId,
                                                         config.merchant_private_key,
                                                         "json",
                                                         config.version,
                                                         config.sign_type,
                                                         config.alipay_public_key,
                                                         config.charset);
                }
                return client;
            }
            if (config != null)
            {
                var newClient = new DefaultAopClient(config.serverUrl,
                                                                 config.appId,
                                                                 config.merchant_private_key,
                                                                 "json",
                                                                 config.version,
                                                                 config.sign_type,
                                                                 config.alipay_public_key,
                                                                 config.charset);
                clients.Add(config, newClient);
                return newClient;
            }
            else
            {
                return clients[config];
            }
        }

        public static IAopClient GetAopClient(AliPayConfig config)
        {
            return Clients(config);
        }

    }
}
