/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */

package net.ranides.assira.reflection.util;

import net.ranides.assira.collection.maps.OpenMap;

import java.lang.annotation.Annotation;
import java.util.Map;

/**
 * This builder can be used to dynamically create object which looks like annotation
 * with specified parameters. It uses {@link AnnotationUtils} under the hood.
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @param <T> T
 */
public final class AnnotationBuilder<T extends Annotation> {
    
    private final Class<T> type;
    
    private final Map<String,Object> params = new OpenMap<>();

    /**
     * Creates new builder for annotation type
     *
     * @param type annotation
     */
    public AnnotationBuilder(Class<T> type) {
        this.type = type;
    }

    /**
     * Defines value for annotation parameter with specified name.
     *
     * @param name name of parameter (method name)
     * @param value value of parameter (method return value)
     * @return this
     */
    public AnnotationBuilder<T> param(String name, Object value) {
        params.put(name, value);
        return this;
    }

    /**
     * Creates object which looks like annotation
     *
     * @return annotation instance
     */
    public T result() {
        return AnnotationUtils.make(type, params);
    }
    
}
