package com.red.circle.other.infra.database.rds.entity.pet;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.red.circle.framework.mybatis.entity.TimestampBaseEntity;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 我的宠物收益明细.
 * </p>
 *
 * @author pengshigang
 * @since 2021-10-14
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("pet_user_pet_income_details")
public class PetUserPetIncomeDetails extends TimestampBaseEntity {

  private static final long serialVersionUID = 1L;

  /**
   * 主键标识.
   */
  @TableId(value = "id", type = IdType.INPUT)
  private Long id;

  /**
   * 宠物主人ID.
   */
  @TableField("user_id")
  private Long userId;

  /**
   * 宠物ID.
   */
  @TableField("pet_id")
  private Long petId;

  /**
   * 宠物背包ID.
   */
  @TableField("pet_bag_id")
  private Long petBagId;

  /**
   * 收益数量.
   */
  @TableField("total_quantity")
  private BigDecimal totalQuantity;

  /**
   * 收取数量.
   */
  @TableField("charge_quantity")
  private BigDecimal chargeQuantity;

  /**
   * 被偷走数量.
   */
  @TableField("steal_quantity")
  private BigDecimal stealQuantity;

  /**
   * 可以领取时间.
   */
  @TableField("can_receive_time")
  private Timestamp canReceiveTime;

  /**
   * 0.未领取，1.已领取.
   */
  @TableField("receive")
  private Boolean receive;

  /**
   * 版本号码.
   */
  @TableField("pet_version")
  private Integer petVersion;


  /**
   * 剩余量.
   */
  public BigDecimal getRemainingQuantity() {
    if (Objects.isNull(chargeQuantity) || Objects.isNull(stealQuantity)) {
      return BigDecimal.ZERO;
    }
    return chargeQuantity.add(stealQuantity);
  }

  /**
   * 计算可偷取数量.
   */
  public BigDecimal computedStealQuantity() {
    return getStealQuantity()
        .subtract(getStealQuantity().multiply(new BigDecimal("0.1")))
        .setScale(0, RoundingMode.DOWN);
  }
}
