package com.jfinal.club.ws;

import com.jfinal.club.common.model.Docws;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.validate.Validator;

/**
 * @ClassName DocWsValidator
 * @Description TODO
 * @Author caolong
 * @Date 2020/3/24 18:21
 */
public class DocWsValidator extends Validator {


    @Override
    protected void validate(Controller c) {

        setShortCircuit(true);
        setRet(Ret.fail());

        Docws model = c.getModel(Docws.class);
        String rawData = c.getRawData();

        validate(model.getYname(), "msg", "原告姓名不正确");
        validate(model.getYbirthday(), "msg", "原告出生日期不正确");
        validate(model.getYhaddress(), "msg", "原告户籍地址不正确");
        validate(model.getYphone(), "msg", "原告联系电话不正确");
        validate(model.getYcodes(), "msg", "原告证件号码不正确");
        validate(model.getBname(), "msg", "被告证件号码不正确");
        validate(model.getBbirthday(), "msg", "被告出生日期不正确");
        validate(model.getBhaddress(), "msg", "被告户籍地址不正确");
        validate(model.getBxaddress(), "msg", "被告现住地址不正确");
        validate(model.getBphone(), "msg", "被告联系电话不正确");
        validate(model.getBcodes(), "msg", "被告证件号码不正确");
        validate(model.getLawsuit(), "msg", "诉讼请求不正确");
        validate(model.getAccount(), "msg", "事实理由不正确");
        validate(model.getMaterial(), "msg", "证据材料名称不正确");
        validate(model.getText(), "msg", "证据内容不正确");
        validate(model.getXaddress(), "msg", "现住地址不正确");

    }

    public void validate(String value, String errorKey, String errorMessage) {
        if (value == null || "".equals(value)) {    // 经测试,form表单域无输入时值为"",跳格键值为"\t",输入空格则为空格" "
            addError(errorKey, errorMessage);
        }
    }

    @Override
    protected void handleError(Controller c) {
        Ret ret = getRet();
        c.renderJson(ret);
    }
}
