package org.springblade.modules.payment.service.impl;

import org.springblade.common.enums.OrderType;
import org.springblade.modules.payment.entity.SuccessParams;
import org.springblade.modules.payment.event.AgentChargeEvent;
import org.springblade.modules.payment.event.MallChargeEvent;
import org.springblade.modules.payment.event.UserPayEvent;
import org.springblade.modules.payment.service.IPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

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

	@Autowired
	private ApplicationEventPublisher eventPublisher;

	@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;
			default: return;

		}
	}



}
