using Fuel.Payment.Core;
using Fuel.Payment.Core.Enum;
using Fuel.Payment.Core.Models;
using Fuel.Payment.Service.Factory;
using Org.BouncyCastle.Asn1.X509;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using WayneCloud.Models;
using ElectronicOrderModel = Fuel.Payment.Core.Models.ElectronicOrderModel;
using FuelOrderDetailModel = Fuel.Payment.Core.Models.FuelOrderDetailModel;

namespace Fuel.Payment.Service.Pay
{
    public class PayService: IPayService
    {
        public async Task<ServiceResponse> PerformElectronicProcess()
        {
            string billNumber = SequenceNumber.Next();
            ElectronicOrderModel eOrder = new ElectronicOrderModel
            {
                Channel = "UNION_SCAN",
                IsRefund = false,
                AuthCode = "284543326353324755",
                BillNumber = billNumber,
                NetAmount = 0.01M,
                Title = "Wayne Payment",
                FuelOrderDetails = new List<FuelOrderDetailModel>(),
                OperatorId = "001",
                SiteId = "66668888",
                Config = ""
            };
            var eProcessor = AsyncPaymentProcessorFactory.Default.Get(eOrder);
            var payConfig = await eProcessor.Initialize(eOrder).ConfigureAwait(false);
            eOrder.Config = payConfig.electronicOrderModel?.Config;
            var genericResponseAlipay = await eProcessor.Process(eOrder).ConfigureAwait(false);
            return new ServiceResponse { StatusCode = HttpStatusCode.OK, Data = null };
        }
        private string GetPaymentChannelByPaymentId(PaymentID paymentID)
        {
            var channel = String.Empty;
            switch (paymentID)
            {
                case PaymentID.AliPay:
                    channel = "ALI_SCAN";
                    break;
                case PaymentID.AliPayQrScan:
                    channel = "ALI_ORDER_SCAN";
                    break;
                case PaymentID.WechatPay:
                    channel = "WX_SCAN";
                    break;
                case PaymentID.WechatQrScan:
                    channel = "WX_ORDER_SCAN";
                    break;
                case PaymentID.AllInPay:
                    channel = "ALL_IN_SCAN";
                    break;
                case PaymentID.AllInPayV2:
                    channel = "ALL_IN_SCAN_V2";
                    break;
                case PaymentID.MembershipMobilePay:
                case PaymentID.MiniProgram:
                    channel = "WECHAT_MINIPROGRAM_PAY";
                    break;
                case PaymentID.IcbcPay:
                    channel = "ICBC_SCAN";
                    break;
                case PaymentID.IcbcPayQrScan:
                    channel = "ICBC_ORDER_SCAN";
                    break;
                case PaymentID.MiniUnionPay:
                    channel = "UNION_MINI";
                    break;
                case PaymentID.UnionPay:
                    channel = "UNION_SCAN";
                    break;
                case PaymentID.GrgbankingPay:
                    channel = "GRG_SCAN";
                    break;
                default:
                    break;
            }
            return channel;
        }
    }
}
