package com.webchat.domain.vo.response.lottery;

import com.webchat.common.constants.LotteryConstants;
import com.webchat.common.exception.BusinessException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @Author 程序员七七
 * @webSite https://www.coderutil.com
 * @Date 2022/11/17 01:01
 * @description
 */
@Data
public class LotteryActivityVO extends LotteryActivityBaseVO {

    @ApiModelProperty("抽奖选项")
    private List<LotteryItemVO> items;


    public void validateIntegral() {
        Assert.isTrue(getIntegral() != null && getIntegral() > 0, "抽奖积分配置异常！");
    }

    public void validateRunningStatus() {
        Integer status = getStatus();
        if (LotteryConstants.LotteryActivityStatus.RUNNING.getStatus().equals(status)) {
            return;
        }
        if (LotteryConstants.LotteryActivityStatus.PREPARATION.getStatus().equals(status)) {
            throw new BusinessException("活动筹备中！");
        }
        if (LotteryConstants.LotteryActivityStatus.CLOSED.getStatus().equals(status)) {
            throw new BusinessException("活动已结束！");
        }
        if (LotteryConstants.LotteryActivityStatus.DELETED.getStatus().equals(status)) {
            throw new BusinessException("活动已经下线！");
        }
    }
}
