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

import com.bonus.canteen.core.marketing.util.EnumUtil;
import com.bonus.canteen.core.marketing.v2.rule.price.constants.RulePriceLimitEnum;
import com.bonus.canteen.core.marketing.v2.rule.price.handler.deductionfull.constants.DiscountTypeEnum;
import com.bonus.canteen.core.marketing.v2.rule.price.handler.deductionfull.constants.PriceTypeEnum;
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 PriceDeductionFullDTO {
   @ApiModelProperty("优惠类型：1满减，2满折")
   private Integer discountType;
   @ApiModelProperty("计价方式：1阶梯，2循环")
   private Integer priceType;
   @ApiModelProperty("适用菜品：1全部菜品，2指定类别，3指定菜品 （后续实现）")
   private Integer dishType;
   @ApiModelProperty("限制类型")
   private Integer limitType;
   @ApiModelProperty("限制次数")
   private Integer maxCount;
   @ApiModelProperty("阶梯信息")
   private List<PriceDeductionFullItemDTO> items;

   public String toString() {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append("优惠类型：").append(DiscountTypeEnum.getValueByKey(this.getDiscountType())).append("<br/>计价方式：").append(PriceTypeEnum.getValueByKey(this.getPriceType())).append("<br/>限制类型：").append(Objects.isNull(this.getLimitType()) ? "无" : EnumUtil.getValueByKey(RulePriceLimitEnum.class, this.getLimitType())).append("<br/>上限次数：").append(Objects.isNull(this.getMaxCount()) ? "无" : this.getMaxCount()).append("<br/>");
      AtomicInteger index = new AtomicInteger(1);
      this.items.forEach((e) -> {
         stringBuilder.append("优惠阶级").append(index.get()).append("，").append("门槛金额：").append(e.getDoorAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)).append("，优惠金额：").append(e.getDiscount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)).append("<br/>");
         index.getAndIncrement();
      });
      return stringBuilder.toString();
   }

   public Integer getDiscountType() {
      return this.discountType;
   }

   public Integer getPriceType() {
      return this.priceType;
   }

   public Integer getDishType() {
      return this.dishType;
   }

   public Integer getLimitType() {
      return this.limitType;
   }

   public Integer getMaxCount() {
      return this.maxCount;
   }

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

   public void setDiscountType(final Integer discountType) {
      this.discountType = discountType;
   }

   public void setPriceType(final Integer priceType) {
      this.priceType = priceType;
   }

   public void setDishType(final Integer dishType) {
      this.dishType = dishType;
   }

   public void setLimitType(final Integer limitType) {
      this.limitType = limitType;
   }

   public void setMaxCount(final Integer maxCount) {
      this.maxCount = maxCount;
   }

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

   public PriceDeductionFullDTO(final Integer discountType, final Integer priceType, final Integer dishType, final Integer limitType, final Integer maxCount, final List<PriceDeductionFullItemDTO> items) {
      this.discountType = discountType;
      this.priceType = priceType;
      this.dishType = dishType;
      this.limitType = limitType;
      this.maxCount = maxCount;
      this.items = items;
   }
}
