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.other.inner.enums.material.PropsCurrencyType;
import com.red.circle.tool.core.text.StringUtils;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import lombok.Data;

/**
 * 道具商店商品.
 *
 * @author pengliang on 2021/5/29
 */
@Data
public class PropsStoreCommodity implements Serializable, PropsCurrencyTypesFilter {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 主键标识.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long id;

  /**
   * 归属平台.
   */
  private String sysOrigin;

  /**
   * 道具类型.
   */
  private PropsCommodityType propsType;

  /**
   * 付费类型.
   */
  private String currencyTypes;

  /**
   * 有效天数.
   */
  private String validDays;

  /**
   * 标签.
   */
  private String label;

  /**
   * 道具优惠比率.
   */
  private BigDecimal discount;

  /**
   * 0.下架 1.上架.
   */
  private Boolean shelfStatus;

  /**
   * 道具能力扩展.
   */
  private PropsAbility propsAbility;

  /**
   * 道具扩展能力
   */
  private NobleVipAbility nobleVipAbility;

  /**
   * 道具资源.
   */
  private PropsResources propsResources;

  /**
   * 道具价格
   */
  private List<PropsPrice> propsPrices;

  /**
   * 钻石价格.
   */
  private List<PropsPrice> diamondPrices;

  @Override
  public boolean filterCurrency(PropsCurrencyType type) {
    return Objects.nonNull(type) && StringUtils.isNotBlank(currencyTypes) && currencyTypes
        .contains(type.name());
  }

  /**
   * 计算价格.
   */
  public BigDecimal calculatePropsPrices(Integer days) {
    return PropsPrice.of(days, propsResources.getAmount()).getAmount();
  }

  /**
   * 计算折扣价.
   */
  public BigDecimal calculatePropsDiscountPrices(Integer days, BigDecimal discountRatio) {
    return PropsPrice.of(days, propsResources.getAmount(), discountRatio).getDiscountAmount();
  }

  /**
   * 获取资源id.
   */
  public Long propsResourceId() {
    return propsResources.getId();
  }

  /**
   * 道具金额.
   */
  public BigDecimal propsResourceAmount() {
    return propsResources.getAmount();
  }


}
