package com.red.circle.other.infra.database.mongo.entity.game.luck;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.google.common.collect.Lists;
import com.red.circle.tool.core.date.TimestampUtils;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

/**
 * luck box 抽奖.
 *
 * @author pengliang on 2022/7/28
 */
@Data
@Accessors(chain = true)
@Document("game_lucky_box_draw")
@EqualsAndHashCode(callSuper = false)
public class GameLuckyBoxDraw implements Serializable {

  private static final long serialVersionUID = 1L;

  /**
   * 记录编号.
   */
  @Id
  private Long id;

  /**
   * 系统.
   */
  private String sysOrigin;

  /**
   * 用户id.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long userId;

  /**
   * 门票.
   */
  private BigDecimal tickets;

  /**
   * 抽奖次数.
   */
  private Integer lotterySize;

  /**
   * 中奖道具.
   */
  private List<GameLuckyBoxProps> luckProps;

  /**
   * 礼物总价值.
   */
  private BigDecimal giftTotalAmount;

  /**
   * 盈亏.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private BigDecimal earn;

  /**
   * 幸运-抽成金额.
   */
  private BigDecimal luckyDrawAmount;

  /**
   * 幸运抽成-比率.
   */
  private BigDecimal luckyDrawRatio;

  /**
   * 投入奖金池金额-抽成.
   */
  private BigDecimal poolPutAmount;

  /**
   * 投入奖金池金额-比率.
   */
  private BigDecimal poolPutRatio;

  /**
   * 日志.
   */
  private List<GameLuckyBoxLog> logs;

  /**
   * 创建时间.
   */
  private Timestamp createTime;

  /**
   * 过期时间.
   */
  private Timestamp expiredTime;

  public void addLog(String content) {
    if (Objects.isNull(logs)) {
      logs = Lists.newArrayList();
    }
    logs.add(new GameLuckyBoxLog()
        .setContent(content)
        .setCreateTime(TimestampUtils.now()));
  }
}
