package com.yonge.cooleshow.biz.dal.dto;

import com.google.common.collect.Lists;
import com.yonge.cooleshow.biz.dal.entity.ActivityPlan;
import com.yonge.cooleshow.biz.dal.entity.ActivityPlanEvaluation;
import com.yonge.cooleshow.biz.dal.entity.ActivityPlanStandard;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.common.enums.EStatus;
import com.yonge.cooleshow.common.enums.RewardTypeEnum;
import com.yonge.cooleshow.common.enums.UnitEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.text.MessageFormat;
import java.util.List;
import java.util.Optional;

/**
 * @Author: liweifan
 * @Data: 2022-08-04 10:19:49
 */
@ApiModel(value = "ActivityPlanDto对象", description = "活动计划表数据传输对象")
public class ActivityPlanDto extends ActivityPlan {
	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "操作人id",hidden = true)
	private Long userId;

	@ApiModelProperty(value = "活动计划-评测活动拓展")
	private ActivityPlanEvaluation planEvaluation;

	@ApiModelProperty(value = "活动计划-达标赠送活动拓展")
	private ActivityPlanStandard planStandard;
	@ApiModelProperty(value = "分享活动-奖品信息")
	private List<RewardItem> rewardItems;

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public ActivityPlanEvaluation getPlanEvaluation() {
		return planEvaluation;
	}

	public void setPlanEvaluation(ActivityPlanEvaluation planEvaluation) {
		this.planEvaluation = planEvaluation;
	}

	public ActivityPlanStandard getPlanStandard() {
		return planStandard;
	}

	public void setPlanStandard(ActivityPlanStandard planStandard) {
		this.planStandard = planStandard;
	}

	public List<RewardItem> getRewardItems() {
		return Optional.ofNullable(rewardItems).orElse(Lists.newArrayList());
	}

	public void setRewardItems(List<RewardItem> rewardItems) {
		this.rewardItems = rewardItems;
	}

	/**
	 * 分享活动-奖品信息
	 */
	@Data
	@NoArgsConstructor
	@AllArgsConstructor
	public static class RewardItem implements Serializable {

		private Long activityId; // 业务更新活动ID
		private String rewardClient;
		private String rewardName;
		private RewardTypeEnum rewardType;
		private String rewardDescribe;
		private String imgUrl;
		private Integer stock;
		private Integer num;
		private UnitEnum unit; // 更新奖品会员类型
		private Integer status;
		private Double discountPrice; // 更新优惠价格

		public Long getActivityId() {
			return activityId;
		}

		public String getRewardClient() {
			return Optional.ofNullable(rewardClient).orElse(ClientEnum.STUDENT.getCode());
		}

		public String getRewardName() {
			return Optional.ofNullable(rewardName).orElse(MessageFormat.format("{0}会员", getUnit().getMsg()));
		}

		public RewardTypeEnum getRewardType() {
			return Optional.ofNullable(rewardType).orElse(RewardTypeEnum.VIP);
		}

		public String getRewardDescribe() {

			return Optional.ofNullable(rewardDescribe).orElse(getRewardName());
		}

		public String getImgUrl() {
			return Optional.ofNullable(imgUrl).orElse("");
		}

		public Integer getStock() {
			return Optional.ofNullable(stock).orElse(1);
		}

		public Integer getNum() {
			return Optional.ofNullable(num).orElse(1);
		}

		public UnitEnum getUnit() {
			return Optional.ofNullable(unit).orElse(UnitEnum.MONTH);
		}

		public Integer getStatus() {
			return Optional.ofNullable(status).orElse(EStatus.DELETE.getValue());
		}

		public Double getDiscountPrice() {
			return Optional.ofNullable(discountPrice).orElse(0D);
		}
	}

	/**
	 * 活动奖品-逻辑映射关系
	 */
	@Data
	@Builder
	@NoArgsConstructor
	@AllArgsConstructor
	public static class ActivityRewardRecord implements Serializable {

		private Long activityId;
		private Long rewardId;
		private Integer rewardNum;
	}
}