package org.spbu.benchmark.web;

import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.List;

import org.spbu.benchmark.Action;
import org.spbu.benchmark.ActionResult;
import org.spbu.benchmark.BenchmarkException;
import org.spbu.benchmark.LoggingSupport;
import org.spbu.benchmark.Scenario;
import org.spbu.benchmark.ScenarioResult;

public class HttpScenario extends LoggingSupport implements Scenario {
	private List<HttpCookie> cookies;
	private List<HttpAction> actions;
	public HttpScenario(){
		this.actions = new ArrayList<HttpAction>();
		this.cookies = new ArrayList<HttpCookie>();
	}

	public List<HttpAction> getActions() {
		return actions;
	}

	public void addAction(Action action) {
		this.actions.add((HttpAction)action);
	}

	public ScenarioResult start() throws BenchmarkException {

		List<ActionResult> actionResults = new ArrayList<ActionResult>();
		long time = 0;
		if(actions!=null)
		for(Action action : actions){
			((HttpAction)action).setCookies(cookies);
			ActionResult actionResult = action.invoke();
	        time += actionResult.getTime();
	        actionResults.add(actionResult);
		}
		HttpScenarioResult result = new HttpScenarioResult(actionResults,true,time);
		return result;
	}
	public void kill(){
		
	}
}
