package org.xbib.settings.datastructures.json;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.xbib.datastructures.api.Node;
import org.xbib.datastructures.api.Parser;
import org.xbib.datastructures.tiny.TinyMap;
import org.xbib.settings.AbstractSettingsLoader;
import org.xbib.datastructures.api.DataStructure;
import org.xbib.datastructures.json.tiny.Json;
import java.util.Set;

public class JsonSettingsLoader extends AbstractSettingsLoader {

    public JsonSettingsLoader() {
    }

    @Override
    public DataStructure dataStructure() {
        return new Json();
    }

    @Override
    public Set<String> suffixes() {
        return Set.of("json");
    }

    @Override
    protected Map<String, String> load(Parser parser, Reader reader) throws IOException {
        List<CharSequence> path = new ArrayList<>();
        TinyMap.Builder<String, String> map = TinyMap.builder();
        Node<?> node = parser.parse(reader);
        parseObject(node, map, path, null);
        return map.build();
    }
}
