package org.apache.seatunnel.api.configuration.custom;

import com.google.auto.service.AutoService;
import org.apache.seatunnel.api.configuration.ConfigAdapter;
import org.apache.seatunnel.common.utils.FileUtils;
import org.apache.seatunnel.common.utils.JsonUtils;
import org.apache.seatunnel.shade.com.fasterxml.jackson.core.type.TypeReference;

import java.nio.file.Path;
import java.util.Map;

@AutoService(ConfigAdapter.class)
public class JsonConfigAdapter implements ConfigAdapter {

    @Override
    public String[] extensionIdentifiers() {
        return new String[]{"json"};
    }

    @Override
    public Map<String, Object> loadConfig(Path configFilePath) {
        String configJson = FileUtils.readFileToStr(configFilePath);
        return JsonUtils.parseObject(configJson, new TypeReference<Map<String, Object>>() {});
    }
}
