package com.red.circle.other.inner.model.cmd.activity.lottery;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.Data;
import lombok.experimental.FieldDefaults;

/**
 * @author pengliang on 2021/11/22
 */
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Prizes implements Serializable {

  private static final long serialVersionUID = 1L;

  /**
   * 背景.
   */
  String background;

  /**
   * 字体.
   */
  List<Fonts> fonts;

  /**
   * 图片.
   */
  List<Imgs> imgs;

  /**
   * 扩展属性.
   */

  /**
   * 字体选中下标.
   */
  String fontIndex;

  /**
   * 图片选中下标.
   */
  String imageIndex;

  /**
   * 库存.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  Long inStock;

  /**
   * 消耗库存.
   */
  Long consumeInStock;

  /**
   * 奖品信息.
   */
  PrizeContent prize;

  /**
   * 概率.
   */
  BigDecimal probability;

  /**
   * 奖品编号.
   */
  String code;

  /**
   * true 不限量, false 限量
   */
  Boolean unlimited;

  public boolean checkAvailableInStock() {
    if (Objects.equals(unlimited, Boolean.TRUE)) {
      return Boolean.TRUE;
    }
    if (Objects.isNull(this.inStock) || this.inStock <= 0) {
      return false;
    }
    if (Objects.isNull(this.consumeInStock)) {
      return true;
    }
    return this.consumeInStock < this.inStock;
  }
}
