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

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.core.marketing.v2.rule.price.constants.RulePriceEnum;
import com.bonus.core.marketing.v2.rule.price.handler.RulePriceHandler;
import com.bonus.core.marketing.v2.rule.price.handler.discount.dto.PriceDiscountDTO;

public interface PriceDiscountHandlerExtension extends RulePriceHandler {
   default Integer getRuleType() {
      return RulePriceEnum.RULE_DISCOUNT.getKey();
   }

   default String checkRuleInfo(String ruleInfo) {
      PriceDiscountDTO rule = (PriceDiscountDTO)JSONObject.parseObject(ruleInfo, PriceDiscountDTO.class);
      if (CollUtil.isEmpty(rule.getItems())) {
         throw new ServiceException("规则配置有误");
      } else {
         return rule.toString();
      }
   }
}
