package com.ruoyi.xq.manager.systemconfig;


import cn.hutool.core.util.NumberUtil;
import com.ruoyi.common.utils.StringUtils;
import lombok.Getter;

@Getter
public class RangeIntegerSystemConfigCheck implements ISystemConfigCheck {

    private final Integer minNum;
    private final Integer maxNum;
    public RangeIntegerSystemConfigCheck(Integer minNum,Integer maxNum) {
        this.minNum = minNum;
        this.maxNum = maxNum;
    }

    @Override
    public SystemCheckResp check(String value) {
        if(StringUtils.isEmpty(value)){
            return SystemCheckResp.fail("该配置必填");
        }
        String errorNum = String.format("请填写正确的整数，范围[%s,%s]", minNum, maxNum);
        boolean b = NumberUtil.isLong(value);
        if(!b){
            return SystemCheckResp.fail(errorNum);
        }
        int of = Integer.parseInt(value);
        if(of < minNum || of > maxNum){
            return SystemCheckResp.fail(errorNum);
        }
        return SystemCheckResp.ok();
    }
}
