package com.bonus.core.marketing.v2.rule.price.handler.sumgive.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.sumgive.dto.PriceSumGiveDTO;

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

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