package org.example.mybatisplus.model.auto;

import lombok.Data;

import java.io.Serializable;

import cn.hutool.core.lang.Pair;
import lombok.NoArgsConstructor;

/**
 * 精细化评分规则项，可json序列化
 *
 */
@Data
@NoArgsConstructor
public class CommonLogicFineRuleModel implements Serializable {
    private static final long serialVersionUID = -6389402890130074848L;

    /**
     * 精细化评分规则项子项
     */
    private CommonLogicRuleItem[] ruleItems;

    public Pair<Boolean, Long> calculate(String val, CommonLogicModel cm) {
        for(CommonLogicRuleItem item: ruleItems) {
            Pair<Boolean, Long> result = item.calculate(val, cm);
            if(result.getKey()) {
                if (result.getValue() <= 0) {
                    // 0分暂处理为false
                    return new Pair<Boolean, Long>(false, 0L);
                }
                return result;
            }
        }
        // score 没有意义
        return new Pair<Boolean, Long>(false, 0L);
    }
}

