package com.cxyxiaomo.epp.PageTable.utils;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

public class FieldValidateBuilder {

    private JSONObject validates;

    public static FieldValidateBuilder create() {
        FieldValidateBuilder builder = new FieldValidateBuilder();
        builder.validates = new JSONObject();
        return builder;
    }

    public FieldValidateBuilder add(String field, FieldRuleBuilder fieldRuleBuilder) {
        JSONArray jsonArray = validates.getJSONArray(field);
        if (jsonArray == null) {
            jsonArray = new JSONArray();
        }
        jsonArray.add(fieldRuleBuilder.build());
        validates.put(field, jsonArray);
        return this;
    }

    public JSONObject build() {
        return validates;
    }
}
