package com.bonus.canteen.core.marketing.v2.rule.price.handler.deductionfixed.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 PriceDeductionFixedDTO {
   @ApiModelProperty("明细")
   private List<PriceDeductionFixedItemDTO> items;

   public String toString() {
      StringBuilder stringBuilder = new StringBuilder();
      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("扣费金额：").append(Objects.isNull(e.getDoorAmount()) ? "按原价" : e.getDoorAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)).append("，优惠金额：").append(Objects.isNull(e.getDiscount()) ? BigDecimal.ZERO : e.getDiscount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)).append("<br/>");
         index.getAndIncrement();
      });
      return stringBuilder.toString();
   }

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

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

   public PriceDeductionFixedDTO(final List<PriceDeductionFixedItemDTO> items) {
      this.items = items;
   }
}
