package org.implab.gradle.common.json;

import org.gradle.api.provider.Provider;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

public class DefaultJsonObjectSpec implements GroovyObjectSpec {

    private final Map<String, Object> values = new LinkedHashMap<>();

    @Override
    public void set(String key, Object value) {
        if (value instanceof Provider<?>) {
            throw new IllegalArgumentException(
                    "Providers are not allowed inside nested JSON objects; " +
                            "use top-level metadata.set(\"" + key + "\", provider) instead.");
        }
        values.put(key, value);
    }

    public Map<String, Object> toMap() {
        return Collections.unmodifiableMap(values);
    }
}