package com.xmomen.framework.web.exceptions;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.Iterator;

@Deprecated
public class ArgumentValidException extends Exception{
    // 定义一个BindingResult类型的私有变量
    private final BindingResult bindingResult;

    // 构造函数，传入一个BindingResult类型的参数
    public ArgumentValidException(BindingResult bindingResult) {
        this.bindingResult = bindingResult;
    }

    // 返回BindingResult类型的变量
    public BindingResult getBindingResult() {
        return this.bindingResult;
    }

    // 返回一个字符串，包含验证失败的参数索引、错误数量和所有错误信息
    public String getMessage() {
        StringBuilder sb = (new StringBuilder("Validation failed for argument at index ")).append(", with ").append(this.bindingResult.getErrorCount()).append(" error(s): ");
        Iterator var2 = this.bindingResult.getAllErrors().iterator();

        while(var2.hasNext()) {
            ObjectError error = (ObjectError)var2.next();
            sb.append("[").append(error).append("] ");
        }

        return sb.toString();
    }
}
