package com.cxyxiaomo.epp.PageTable.utils;

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

import java.util.HashMap;

public class FieldMapperBuilder {

    private JSONArray columns;

    public static FieldMapperBuilder create() {
        FieldMapperBuilder builder = new FieldMapperBuilder();
        builder.columns = new JSONArray();
        return builder;
    }

    // public PageTableFieldMapperBuilder add(String prop, String label, List mapper) {
    //     if (mapper == null || mapper.size() == 0) {
    //         return this;
    //     }
    //     JSONObject jsonObject = new JSONObject(3);
    //     jsonObject.put("key", prop);
    //     jsonObject.put("value", label);
    //     jsonObject.put("mapper", mapper);
    //     columns.add(jsonObject);
    //     return this;
    // }

    public FieldMapperBuilder add(String prop, String label, HashMap mapper) {
        JSONObject jsonObject = new JSONObject(3);
        jsonObject.put("key", prop);
        jsonObject.put("value", label);
        jsonObject.put("mapper", mapper);
        columns.add(jsonObject);
        return this;
    }

    public JSONArray build() {
        return columns;
    }
}
