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

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

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