package org.bench4q.agent.plugin.basic.context;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.bench4q.agent.plugin.Constructor;
import org.bench4q.agent.plugin.Parameter;
import org.bench4q.agent.plugin.ParameterBarn;
import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.plugin.behavior.Behavior;
import org.bench4q.agent.plugin.behavior.BehaviorType;
import org.bench4q.agent.utils.Type.SupportTypes;

@Plugin("Context")
public class Context extends ParameterBarn {
	private List<String> values;

	@Constructor
	public Context(
			@Parameter(type = SupportTypes.Field, value = "testId") String testId) {
		super(testId);
		this.values = new ArrayList<String>();
	}

	@Behavior(value = "Set", type = BehaviorType.CONTROL_BEHAVIOR)
	public void set(
			@Parameter(value = "toSave", type = SupportTypes.Field) String toSave) {
		this.values.add(toSave);
	}

	@Override
	public String getValue(String var) {
		Random random = new Random();
		int index = random.nextInt(this.values.size());
		return this.values.get(index);
	}

}
