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

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

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