package org.example.mybatisplus.model.auto;

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

import java.io.Serializable;

/**
 * 精细化评分规则项子项，可json序列化
 *
 * @author snows
 * @date 2025/01/17
 */
@Data
public class CommonLogicRuleItem implements Serializable {
    private static final long serialVersionUID = -320800240067075225L;

    /**
     * 规则字段类型
     */
    private CommonType.RuleType ruleType;

    /**
     * 规则值，比如："keyword1,keyword2" 或者 200
     */
    private String rule;

    /**
     * 指标值
     */
    private long targetScore;

    /**
     * 判断逻辑类型
     */
    private CommonType.LogicType logicType;

    /**
     * 计算
     *
     * @param val 值
     * @return {@link Pair }<{@link Boolean }, {@link Integer }> 计算结果
     */
    public Pair<Boolean, Long> calculate(String val, CommonLogicModel cm) {
        return new Pair<>(CommonLogicModel.of(logicType, rule).calculate_internal(val), targetScore);
    }
}
