package com.red.circle.other.app.dto.cmd.material;

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.inner.enums.material.PropsCurrencyType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 购买道具.
 *
 * @author pengliang on 2021/1/22
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class PropsPurchasingCmd extends AppExtCommand {

  /**
   * 道具id.
   *
   * @eo.required
   */
  @NotNull(message = "propsId required.")
  private Long propsId;

  /**
   * 道具类型.
   *
   * @eo.required
   */
  @Deprecated
  @NotBlank(message = "type required.")
  private String type;

  /**
   * 货币类型.
   *
   * @eo.required
   */
  @NotNull(message = "currencyType required.")
  private PropsCurrencyType currencyType;

  /**
   * 接收用户id.
   */
  private Long acceptUserId;

  /**
   * 天数.
   *
   * @eo.required
   */
  @NotNull(message = "days required.")
  private Integer days;

  /**
   * 如果接受人不存或者是自己在表示购买.
   */
  public boolean isPurchasing() {
    return Objects.isNull(acceptUserId) || Objects.equals(acceptUserId, requiredReqUserId());
  }

  /**
   * 道具接收人.
   */
  public Long acceptUser() {
    return Objects.nonNull(acceptUserId) ? acceptUserId : requiredReqUserId();
  }

  /**
   * 是否是金币支付.
   */
  public boolean isPayGold() {
    return Objects.equals(currencyType, PropsCurrencyType.GOLD);
  }

  /**
   * 是否是钻石支付.
   */
  public boolean isPayDiamond() {
    return Objects.equals(currencyType, PropsCurrencyType.DIAMOND);
  }

  /**
   * 是否是免费.
   */
  public boolean isFree() {
    return Objects.equals(currencyType, PropsCurrencyType.FREE);
  }

}
