package pl.edu.agh.sloniec.client.provider;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import pl.edu.agh.sloniec.client.entity.LevelEnum;

/**
 * Created by Jakub Sloniec on 14.03.2016.
 */
public class ConnProvider {

	private static Connection init(String url, Connection.Method m) {
		return Jsoup.connect(url).ignoreContentType(true).method(m).timeout(30000);
	}

	static Connection getLoginConnection(String login) {
		String url = UrlProvider.getLoginUrl(login);
		Connection.Method m = Connection.Method.GET;

		return init(url, m);
	}

	static Connection getServerParametersConnection() {
		String url = UrlProvider.getServerParametersUrl();
		Connection.Method m = Connection.Method.GET;

		return init(url, m);
	}

	static Connection getSetParametersConnection(Boolean clientAwareness, Boolean reactivePreprocessing) {
		String url = UrlProvider.getSetParametersUrl(String.valueOf(clientAwareness), String.valueOf(reactivePreprocessing));
		Connection.Method m = Connection.Method.PUT;

		return init(url, m);
	}


	static Connection getNewTaskConnection(String projectId, String userId, LevelEnum difficulty) {
		String url = UrlProvider.getNewTaskUrl(projectId, userId, difficulty);
		Connection.Method m = Connection.Method.GET;

		return init(url, m);
	}

	static Connection getReturnTaskConnection(String taskId) {
		String url = UrlProvider.getReturnTaskUrl(taskId);
		Connection.Method m = Connection.Method.POST;

		return init(url, m);
	}

	static Connection getNewProjectConnection(String size, String userId) {
		String url = UrlProvider.getNewProjectUrl(size, userId);
		Connection.Method m = Connection.Method.POST;

		return init(url, m);
	}

	static Connection getProjectConnection() {
		String url = UrlProvider.getProjectUrl();
		Connection.Method m = Connection.Method.GET;

		return init(url, m);
	}

	static Connection getCleanProjectsConnection() {
		String url = UrlProvider.getCleanProjectsUrl();
		Connection.Method m = Connection.Method.DELETE;

		return init(url, m);
	}

	static Connection getCleanTasksConnection() {
		String url = UrlProvider.getCleanTasksUrl();
		Connection.Method m = Connection.Method.DELETE;

		return init(url, m);
	}

}
