package com.slodon.b2b2c.vo.promotion;

import com.slodon.b2b2c.core.constant.DrawConst;
import com.slodon.b2b2c.core.i18n.Language;
import com.slodon.b2b2c.core.util.FileUrlUtil;
import com.slodon.b2b2c.promotion.pojo.DrawPrize;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.io.Serializable;

/**
 * 封装抽奖奖品vo
 */
@Data
@NoArgsConstructor
public class DrawPrizeVO implements Serializable {

    private static final long serialVersionUID = -767394255947765168L;
    @ApiModelProperty("奖项id")
    private Integer prizeId;

    @ApiModelProperty("抽奖活动id")
    private Integer drawId;

    @ApiModelProperty("奖项名称")
    private String prizeName;

    @ApiModelProperty("奖项图片(相对地址)")
    private String prizeImage;

    @ApiModelProperty("奖项图片(绝对地址)")
    private String prizeImageUrl;

    @ApiModelProperty("奖品类型，1-积分，2-优惠券")
    private Integer prizeType;

    @ApiModelProperty("奖品类型，1-积分，2-优惠券")
    private String prizeTypeValue;

    @ApiModelProperty("奖励积分数量")
    private Integer integralNum;

    @ApiModelProperty("奖励优惠券id")
    private Integer couponId;

    @ApiModelProperty("优惠券名称")
    private String couponName;

    @ApiModelProperty("优惠内容")
    private String couponContent;

    @ApiModelProperty("奖励份数")
    private Integer prizeNum;

    @ApiModelProperty("中奖率")
    private Integer rate;

    public DrawPrizeVO(DrawPrize drawPrize) {
        prizeId = drawPrize.getPrizeId();
        drawId = drawPrize.getDrawId();
        prizeName = drawPrize.getPrizeName();
        prizeImage = drawPrize.getPrizeImage();
        prizeImageUrl = FileUrlUtil.getFileUrl(drawPrize.getPrizeImage(), null);
        prizeType = drawPrize.getPrizeType();
        prizeTypeValue = dealPrizeTypeValue(drawPrize.getPrizeType());
        integralNum = drawPrize.getIntegralNum();
        couponId = drawPrize.getCouponId();
        couponName = drawPrize.getCouponName();
        couponContent = drawPrize.getCouponContent();
        prizeNum = drawPrize.getPrizeNum();
        rate = drawPrize.getRate();
    }

    public static String dealPrizeTypeValue(Integer prizeType) {
        String value = "";
        if (StringUtils.isEmpty(prizeType)) return null;
        switch (prizeType) {
            case DrawConst.PRIZE_TYPE_1:
                value = "积分";
                break;
            case DrawConst.PRIZE_TYPE_2:
                value = "优惠券";
                break;
            default:
                return null;
        }
        //翻译
        value = Language.translate(value);
        return value;
    }
}