package com.huiju.estateagents.event;

import com.huiju.estateagents.entity.*;
import com.huiju.estateagents.service.ITaPointsRecordsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author FXF
 * @date 2019-07-30
 */

@Component
@Slf4j
public class EventLisenter {
	
	@Autowired
	private ITaPointsRecordsService taPointsRecordsService;

	/**
	 * 获取积分
	 * @param event
	 */
	@EventListener
	public void handler(EventBus event) {
		switch (event.getType()) {
			case SharePoster:
				getSharePoints((TaShare) event.getSource(), event.getOrgId());
				break;
			case DailyCheckin:
				getCheckinPoints((TaPersonSign) event.getSource(), event.getOrgId());
				break;
			case RecommendCustomer:
				getRecommendCustPoints((TaRecommendCustomer) event.getSource(), event.getOrgId());
				break;
			case SignUpAgent:
				getSignUpPoints((TaPerson) event.getSource(), event.getOrgId());
				break;
			case SharePosterAll:
				getSharePointsAll((String) event.getSource(), event.getOrgId());
				break;

			// 活动核销签到
			case ActivityVerificationSign:
				getActivityVerificationSign((HelpInitiateRecord) event.getSource(), event.getOrgId());
				break;
			// 资料审核成功
			case DocumentVerify:
				getDocumentVerify((TaDocumentVerify) event.getSource(), event.getOrgId());
				break;
			case ActivityCheckin:
				getActivityCheckin((TaActivityDynamicEnlist) event.getSource(), event.getOrgId());
			default:
				break;
		}
	}

	// 普通活动扫码签到
	private void getActivityCheckin(TaActivityDynamicEnlist source, Integer orgId) {
		taPointsRecordsService.checkinActivityPoints(source,orgId);
	}

	// 分享赚积分
	private void getSharePoints(TaShare taShare, Integer orgId) {
		taPointsRecordsService.sharePoints(taShare, orgId);
	}

	// 无限制 分享赚积分
	private void getSharePointsAll(String recommenderId, Integer orgId) {
		taPointsRecordsService.sharePosterAll(recommenderId, orgId);
	}

	// 签到赚积分
	private void getCheckinPoints(TaPersonSign taPersonSign, Integer orgId) { taPointsRecordsService.checkinPoints(taPersonSign, orgId); }

	// 注册送积分
	private void getSignUpPoints(TaPerson taPerson, Integer orgId) { taPointsRecordsService.signUpPoints(taPerson, orgId);}

	// 推荐客户送积分
	private void getRecommendCustPoints(TaRecommendCustomer taRecommendCustomer, Integer orgId) { taPointsRecordsService.recommendCustPoints(taRecommendCustomer, orgId); }

	/**
	 * 活动核销成功送积分
	 */
	private void getActivityVerificationSign(HelpInitiateRecord helpInitiateRecord, Integer orgId) {
		taPointsRecordsService.activityVerificationSign(helpInitiateRecord, orgId);
	}

	/**
	 * 资料审核成功送积分
	 */
	private void getDocumentVerify(TaDocumentVerify taDocumentVerify, Integer orgId) {
		taPointsRecordsService.documentVerify(taDocumentVerify, orgId);
	}
}
