package org.implab.gradle.common.utils;

import java.util.Optional;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.gradle.api.plugins.ExtraPropertiesExtension;

@NonNullByDefault
class ExtraPropsExtension implements ExtraProps {

    private final ExtraPropertiesExtension ext;

    public ExtraPropsExtension(ExtraPropertiesExtension ext) {
        this.ext = ext;
    }

    @Override
    public Set<String> keys() {
        return ext.getProperties().keySet();
    }

    @Override
    public boolean has(String name) {
        return ext.has(name);
    }

    @Override
    public <T> Optional<T> get(String name, Class<T> clazz) {
        return Optional.ofNullable(ext.get(name)).map(clazz::cast);
    }

    @Override
    public void put(String name, Object value) {
        ext.set(name, value);
    }

    @Override
    public void remove(String name) {
        ext.set(name, null);
    }
    
}
