/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.party.activityenroll.wrapper;

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.party.activity.entity.Activity;
import org.springblade.party.activity.service.IActivityService;
import org.springblade.party.activityenroll.entity.ActivityEnroll;
import org.springblade.party.activityenroll.vo.ActivityEnrollVO;
import org.springblade.party.member.entity.Member;
import org.springblade.party.member.service.IMemberService;

import java.util.Objects;

/**
 * 包装类,返回视图层所需的字段
 *
 * @author BladeX
 * @since 2021-04-07
 */

public class ActivityEnrollWrapper extends BaseEntityWrapper<ActivityEnroll, ActivityEnrollVO>  {
	private IMemberService memberService;
	private IActivityService activityService;

	private ActivityEnrollWrapper(IMemberService memberService, IActivityService activityService){
		this.memberService = memberService;
		this.activityService = activityService;
	}

	public static ActivityEnrollWrapper build(IMemberService memberService, IActivityService activityService) {
		return new ActivityEnrollWrapper(memberService,activityService);
 	}

	@Override
	public ActivityEnrollVO entityVO(ActivityEnroll activityEnroll) {
		ActivityEnrollVO activityEnrollVO = Objects.requireNonNull(BeanUtil.copy(activityEnroll, ActivityEnrollVO.class));

		Member member = memberService.getById(activityEnroll.getMemberId());
		if (member != null){
			activityEnrollVO.setMemberName(member.getName());
		}else {
			activityEnrollVO.setMemberName("该党员不存在");
		}

		Activity activity = this.activityService.getById(activityEnroll.getActivityId());
		if (activity != null){
			activityEnrollVO.setActivityName(activity.getName());
			activityEnrollVO.setActivityImg(activity.getImg());
			activityEnrollVO.setActivityBeginTime(activity.getBeginTime());
			activityEnrollVO.setActivityEndTime(activity.getEndTime());
			activityEnrollVO.setIdVerification(activity.getIdVerification());
			activityEnrollVO.setPeopleCount(activity.getPeopleCount() - activity.getRemainingCount());
		}
		//User createUser = UserCache.getUser(activityEnroll.getCreateUser());
		//User updateUser = UserCache.getUser(activityEnroll.getUpdateUser());
		//activityEnrollVO.setCreateUserName(createUser.getName());
		//activityEnrollVO.setUpdateUserName(updateUser.getName());

		return activityEnrollVO;
	}

}
