"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _ = require("lodash");
var utils_1 = require("../utils");
// enum	枚举类型	string	-
// len	字段长度	number	-
// max	最大长度	number	-
// message	校验文案	string	-
// min	最小长度	number	-
// pattern	正则表达式校验	RegExp	-
// required	是否必选	boolean	false
// transform	校验前转换字段值	function(value) => transformedValue:any	-
// type	内建校验类型，可选项	string	'string'
// validator	自定义校验（注意，callback 必须被调用）	function(rule, value, callback)	-
// whitespace	必选时，空格是否会被视为错误	boolean	false
// string: Must be of type string. This is the default type.
// number: Must be of type number.
// boolean: Must be of type boolean.
// method: Must be of type function.
// regexp: Must be an instance of RegExp or a string that does not generate an exception when creating a new RegExp.
// integer: Must be of type number and an integer.
// float: Must be of type number and a floating point number.
// array: Must be an array as determined by Array.isArray.
// object: Must be of type object and not Array.isArray.
// enum: Value must exist in the enum.
// date: Value must be valid as determined by Date
// url: Must be of type url.
// hex: Must be of type hex.
// email: Must be of type email.
function buildMessage(rule, title) {
    // if(rule.required){
    // }
    // if(rule.pattern){
    //  return `${title} 必须符合格式 ${rule.pattern}`
    // }
    return title + " \u4E3A\u5FC5\u586B\u9879\uFF01";
}
// TODO:需要完善
function ruleMessage(column) {
    var rules = [];
    if (column.type == undefined || column.type == 'text' || column.type == 'textarea' || column.type == 'select') {
        rules.push({
            message: '不允许包含特殊字符', validator: function (rule, value, callback, source, options) {
                if (value) {
                    if (utils_1.Const.SPECIAL_CHARACTER.test(value)) {
                        callback(new Error());
                    }
                    else {
                        callback([]);
                    }
                }
                else {
                    callback([]);
                }
            }
        });
    }
    // }
    if (_.isArray(column.rule)) {
        column.rule.map(function (item) {
            if (_.has(item, 'message')) {
                rules.push(item);
            }
            else {
                rules.push(_.assign({}, item, { message: buildMessage(item, column.title) }));
            }
        });
    }
    return rules;
}
exports.ruleMessage = ruleMessage;
;
