package org.springblade.payment.service.impl;

import lombok.AllArgsConstructor;
import org.springblade.common.enums.OrderType;
import org.springblade.payment.callback.trade.*;
import org.springblade.payment.entity.SuccessParams;
import org.springblade.payment.event.*;
import org.springblade.payment.service.IPaymentService;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

/**
 * @author: lianghanqiang
 * @description:
 * @since: 8/5/21 -- 2:34 PM
 */
@Service
@AllArgsConstructor
public class PaymentService implements IPaymentService {

	private ApplicationEventPublisher eventPublisher;
	private AgentChargeCallback agentChargeCallback;
	private MallChargeCallback mallChargeCallback;
	private MallRechargeCallback mallRechargeCallback;
	private MallSendCallback mallSendCallback;
	private ShopSendCallback shopSendCallback;
	private UserPayCallback userPayCallback;
	private UserPayCS userPayCS;
	private UserPointTransferWithdrawCallback userPointTransferWithdrawCallback;
	private UserPointWithdrawCallback userPointWithdrawCallback;
	private UserWithdrawCallback userWithdrawCallback;
	private WeChatPayCallback weChatPayCallback;

//	@Override
//	public void success(SuccessParams successParams) {
//		switch (OrderType.valueOf(successParams.getOrderType())) {
//			case USER_PAY:
//				eventPublisher.publishEvent(new UserPayEvent(successParams));
//				return;
//			case AGENT_CHARGE:
//				eventPublisher.publishEvent(new AgentChargeEvent(successParams));
//				return;
//			case MALL_CHARGE:
//				eventPublisher.publishEvent(new MallChargeEvent(successParams));
//				return;
//			case WECHAT_PAY:
//				eventPublisher.publishEvent(new WeChatPayEvent(successParams));
//				return;
//			case USER_WITHDRAW:
//				eventPublisher.publishEvent(new UserWithdrawEvent(successParams));
//				return;
//			case MALL_SEND:
//				eventPublisher.publishEvent(new MallSendPointEvent(successParams));
//				return;
//			case SHOP_SEND:
//				eventPublisher.publishEvent(new ShopSendPointEvent(successParams));
//				return;
//			case MALL_RECHARGE:
//				eventPublisher.publishEvent(new MallRechargeEvent((successParams)));
//			case USER_POINT_TRANSFER_WITHDRAW:
//				eventPublisher.publishEvent(new UserPointTransferWithdrawEvent(successParams));
//			case USER_POINT_WITHDRAW:
//				eventPublisher.publishEvent(new UserPointWithdrawEvent(successParams));
//			default:
//				return;
//
//		}
//	}

	@Override
	public void success(SuccessParams successParams) {
		switch (OrderType.valueOf(successParams.getOrderType())) {
			case USER_PAY:
				userPayCallback.PaySuccess(new UserPayEvent(successParams));
				return;
			case AGENT_CHARGE:
				agentChargeCallback.PaySuccess(new AgentChargeEvent(successParams));
				return;
			case MALL_CHARGE:
				mallChargeCallback.PaySuccess(new MallChargeEvent(successParams));
				return;
			case WECHAT_PAY:
				weChatPayCallback.handleWeChatPayCallback(new WeChatPayEvent(successParams));
				return;
			case USER_WITHDRAW:
				userWithdrawCallback.PaySuccess(new UserWithdrawEvent(successParams));
				return;
			case MALL_SEND:
				mallSendCallback.handle(new MallSendPointEvent(successParams));
				return;
			case SHOP_SEND:
				shopSendCallback.handle(new ShopSendPointEvent(successParams));
				return;
			case MALL_RECHARGE:
				mallRechargeCallback.PaySuccess(new MallRechargeEvent((successParams)));
				return;
			case USER_POINT_TRANSFER_WITHDRAW:
				userPointTransferWithdrawCallback.PaySuccess(new UserPointTransferWithdrawEvent(successParams));
				return;
			case USER_POINT_WITHDRAW:
				userPointWithdrawCallback.PaySuccess(new UserPointWithdrawEvent(successParams));
				return;
			default:
				return;
		}
	}

	@Override
	public void cs(SuccessParams successParams) {
		switch (OrderType.valueOf(successParams.getOrderType())) {
			case USER_PAY:
				//eventPublisher.publishEvent(new UserPayCsEvent(successParams));
				userPayCS.PaySuccess(new UserPayCsEvent(successParams));
				return;
			default:
				return;
		}

	}
}
