package com.bonus.canteen.core.marketing.v2.rule.price.handler.discount.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

@ApiModel("计价规则详情-打折")
public class PriceDiscountDTO {
   @ApiModelProperty("优惠/上浮上限金额(分)")
   private BigDecimal maxAmount;
   @ApiModelProperty(" 参与打折累计金额（分）")
   private BigDecimal joinAmount;
   @ApiModelProperty("打折比例list，例如第一次：0.8<br/>第二次：0.9<br/>第三次及以后：0.95")
   private List<BigDecimal> items;

   public String toString() {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append("优惠/上浮上限金额(元)：").append(Objects.isNull(this.getMaxAmount()) ? "无" : this.getMaxAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)).append("<br/>参与打折累计金额(元)：").append(Objects.isNull(this.getJoinAmount()) ? "无" : this.getJoinAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)).append("<br/>");
      AtomicInteger index = new AtomicInteger(1);
      this.items.forEach((e) -> {
         if (index.get() == this.items.size()) {
            stringBuilder.append("后续打折：");
         } else {
            stringBuilder.append("第").append(index.get()).append("次打折：");
         }

         stringBuilder.append(e).append("<br/>");
         index.getAndIncrement();
      });
      return stringBuilder.toString();
   }

   public BigDecimal getMaxAmount() {
      return this.maxAmount;
   }

   public BigDecimal getJoinAmount() {
      return this.joinAmount;
   }

   public List<BigDecimal> getItems() {
      return this.items;
   }

   public void setMaxAmount(final BigDecimal maxAmount) {
      this.maxAmount = maxAmount;
   }

   public void setJoinAmount(final BigDecimal joinAmount) {
      this.joinAmount = joinAmount;
   }

   public void setItems(final List<BigDecimal> items) {
      this.items = items;
   }

}
