package org.implab.gradle.common.json.dsl;


import org.gradle.api.provider.Provider;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


public class DefaultJsonArraySpec implements JsonArraySpec {

    private final List<Object> values = new ArrayList<>();

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

    public List<Object> toList() {
        return Collections.unmodifiableList(values);
    }
}
