import { isNumber, isString } from "../is";

// vxe-table自定义校验-算法
function validateCountType(params) {
    return new Promise<void>(async (resolve, reject) => {
        const { row } = params;
        const countType = row.countModel.countType
        if (countType >= 0) {
            resolve(); // 校验通过
        } else {
            reject(new Error('请选择算法')); // 校验不通过
        }
    });
}

// vxe-table自定义校验-第一层的字段
function validateFieldType(params) {
    return new Promise<void>(async (resolve, reject) => {
        const { row, field, rule } = params;
        if (isNumber(row[field]) || isString(row[field])) {
            resolve(); // 校验通过
        } else {
            reject(new Error(rule.message)); // 校验不通过
        }
    });
}

export {
    validateCountType,
    validateFieldType
}