package com.red.circle.other.inner.model.dto.material.props;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.red.circle.other.inner.enums.material.PropsCommodityType;
import com.red.circle.tool.core.date.TimestampUtils;
import java.io.Serial;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 用户道具背包物品.
 * </p>
 *
 * @author pengliang
 * @since 2021-05-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class PropsItem implements Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

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

  /**
   * 道具id.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long propsId;

  /**
   * 类型.
   */
  private PropsCommodityType type;

  /**
   * 天数或数量.
   */
  private Integer validDays;

  /**
   * 类型名称.
   */
  public String getTypeName() {
    return Objects.toString(type);
  }

  /**
   * 当前过期时间.
   */
  public Timestamp thisExpireTime() {
    return TimestampUtils.nowPlusDays(validDays);
  }

  /**
   * 追加过期时间.
   */
  public Timestamp appendExpiredTime(Timestamp sourceTimestamp) {
    return TimestampUtils.expiredPlusDays(sourceTimestamp, validDays);
  }

}
