package com.ruoyi.xq.manager.systemconfig;

import com.ruoyi.common.utils.StringUtils;
import lombok.Getter;

import java.util.List;

@Getter
public class NumberListSystemConfigCheck implements ISystemConfigCheck {
    private Integer minSize;

    public NumberListSystemConfigCheck(Integer minSize) {
        this.minSize = minSize;
    }

    public NumberListSystemConfigCheck() {
    }

    @Override
    public SystemCheckResp check(String value) {
        if(StringUtils.isEmpty(value)){
            return SystemCheckResp.fail("该配置必填");
        }
        String errMessage = String.format("请填写逗号分割的数字,且需要不低于%s个", minSize);
        List<Long> longList = SystemConfigCheckUtil.getArrayListOfLong(value);
        if(longList == null){
            return SystemCheckResp.fail(errMessage);
        }
        if(longList.size() < minSize){
            return SystemCheckResp.fail(errMessage);
        }
        return SystemCheckResp.ok();
    }
}
