package com.bonus.canteen.core.marketing.v2.rule.recharge.handler.timesgift.extension;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.canteen.core.marketing.v2.rule.recharge.constants.RuleRechargeEnum;
import com.bonus.canteen.core.marketing.v2.rule.recharge.handler.RuleRechargeHandler;
import com.bonus.canteen.core.marketing.v2.rule.recharge.handler.timesgift.dto.RechargeTimesGiftDTO;

import java.util.Collection;
import java.util.Objects;

public interface RechargeTimesGiftHandlerExtension extends RuleRechargeHandler {
   @Override
   default Integer getRuleType() {
      return RuleRechargeEnum.RULE_TIMES_GIFT.getKey();
   }

   @Override
   default void checkRuleInfo(String ruleInfo) {
      RechargeTimesGiftDTO giftDTO = (RechargeTimesGiftDTO)JSONObject.parseObject(ruleInfo, RechargeTimesGiftDTO.class);
      if (Objects.isNull(giftDTO) || CollUtil.isEmpty(giftDTO.getItems()) || CollUtil.isEmpty((Collection)giftDTO.getItems().get(0))) {
         throw new ServiceException("规则配置有误");
      }
   }
}
