package com.slodon.b2b2c.vo.promotion;

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

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import static com.slodon.b2b2c.vo.promotion.DrawVO.dealDrawTypeValue;

/**
 * 封装抽奖活动详情vo
 */
@Data
public class DrawDetailVO implements Serializable {

    private static final long serialVersionUID = 3224273327452724171L;
    @ApiModelProperty("抽奖活动id")
    private Integer drawId;

    @ApiModelProperty("抽奖活动名称，最多6个字")
    private String drawName;

    @ApiModelProperty("活动开始时间")
    private Date startTime;

    @ApiModelProperty("活动结束时间")
    private Date endTime;

    @ApiModelProperty("抽奖消耗积分数（活动类型）")
    private Integer integralUse;

    @ApiModelProperty("抽奖消耗积分数（活动类型）")
    private String integralUseValue;

    @ApiModelProperty("活动规则类型，1-每人每天可抽奖n次，2-每人总共可抽奖n次")
    private Integer ruleType;

    @ApiModelProperty("活动规则次数")
    private Integer ruleNum;

    @ApiModelProperty("背景图(相对地址)")
    private String backgroundImage;

    @ApiModelProperty("背景图(绝对地址)")
    private String backgroundImageUrl;

    @ApiModelProperty("正常可用时按钮图片(相对地址)")
    private String availableButtonImage;

    @ApiModelProperty("正常可用时按钮图片(绝对地址)")
    private String availableButtonImageUrl;

    @ApiModelProperty("机会用尽时按钮图片(相对地址)")
    private String chanceOutButtonImage;

    @ApiModelProperty("机会用尽时按钮图片(绝对地址)")
    private String chanceOutButtonImageUrl;

    @ApiModelProperty("是否开启虚拟中奖，0-不开启，1-开启，开启后，中奖名单将加入虚拟中奖数据")
    private Integer openVirtual;

    @ApiModelProperty("活动描述，最多100字")
    private String drawDescription;

    @ApiModelProperty("未中奖提示信息，最多6个字")
    private String losePrizeDescription;

    @ApiModelProperty("未中奖图片(相对地址)")
    private String losePrizeImage;

    @ApiModelProperty("未中奖图片(绝对地址)")
    private String losePrizeImageUrl;

    @ApiModelProperty("抽奖活动类型，1-幸运抽奖，2-大转盘，3-刮刮卡，4-摇一摇，5-翻翻看")
    private Integer drawType;

    @ApiModelProperty("抽奖活动类型，1-幸运抽奖，2-大转盘，3-刮刮卡，4-摇一摇，5-翻翻看")
    private String drawTypeValue;

    @ApiModelProperty("综合中奖率")
    private Integer totalRate;

    @ApiModelProperty("奖项")
    private List<DrawPrizeVO> drawPrizeVOList;

    public DrawDetailVO(Draw draw) {
        drawId = draw.getDrawId();
        drawName = draw.getDrawName();
        startTime = draw.getStartTime();
        endTime = draw.getEndTime();
        integralUse = draw.getIntegralUse();
        integralUseValue = dealIntegralUseValue(draw.getIntegralUse());
        ruleType = draw.getRuleType();
        ruleNum = draw.getRuleNum();
        backgroundImage = draw.getBackgroundImage();
        backgroundImageUrl = FileUrlUtil.getFileUrl(draw.getBackgroundImage(), null);
        availableButtonImage = draw.getAvailableButtonImage();
        availableButtonImageUrl = FileUrlUtil.getFileUrl(draw.getAvailableButtonImage(), null);
        chanceOutButtonImage = draw.getChanceOutButtonImage();
        chanceOutButtonImageUrl = FileUrlUtil.getFileUrl(draw.getChanceOutButtonImage(), null);
        openVirtual = draw.getOpenVirtual();
        drawDescription = draw.getDrawDescription();
        losePrizeDescription = draw.getLosePrizeDescription();
        losePrizeImage = draw.getLosePrizeImage();
        losePrizeImageUrl = FileUrlUtil.getFileUrl(draw.getLosePrizeImage(), null);
        drawType = draw.getDrawType();
        drawTypeValue = dealDrawTypeValue(draw.getDrawType());
        totalRate = draw.getTotalRate();
    }

    public static String dealIntegralUseValue(Integer integralUse) {
        String value = "";
        if (StringUtils.isEmpty(integralUse)) return null;
        if (integralUse == 0) {
            value = "无限制";
        } else {
            value = "每次抽奖使用" + integralUse + "积分";
        }
        //翻译
        value = Language.translate(value);
        return value;
    }

}