package org.testobject.rest.api.appium.common;

import java.net.MalformedURLException;
import java.net.URL;

public final class TestObjectCapabilities {

	public static final URL TESTOBJECT_BASE_ENDPOINT = getURL("https://appium.testobject.com:443");
	public static final URL TESTOBJECT_API_ENDPOINT = toTestObjectApiEndpointUrl(TESTOBJECT_BASE_ENDPOINT);
	public static final URL TESTOBJECT_APPIUM_ENDPOINT = toTestObjectAppiumEndpointURL(TESTOBJECT_BASE_ENDPOINT);

	public static final String TESTOBJECT_API_KEY = "testobject_api_key";
	public static final String TESTOBJECT_TEST_REPORT_ID = "testobject_test_report_id";
	public static final String TESTOBJECT_TEST_REPORT_URL = "testobject_test_report_url";
	public static final String TESTOBJECT_TEST_LIVE_VIEW_URL = "testobject_test_live_view_url";
	public static final String TESTOBJECT_FRAMEWORK_APP_ID = "testobject_framework_app_id";
	public static final String TESTOBJECT_APP_ID = "testobject_app_id";
	public static final String TESTOBJECT_DEVICE = "testobject_device";
	public static final String TESTOBJECT_DEVICE_SESSION_ID = "testobject_device_session_id";
	public static final String TESTOBJECT_SUITE_NAME = "testobject_suite_name";
	public static final String TESTOBJECT_TEST_NAME = "testobject_test_name";
	public static final String TESTOBJECT_APPIUM_VERSION = "testobject_appium_version";
	public static final String TESTOBJECT_DISABLE_VALIDATION = "testobject_disable_validation";
	public static final String TESTOBJECT_NO_RESET = "testobject_no_reset";
	public static final String TESTOBJECT_CACHE_DEVICE = "testobject_cache_device";
	public static final String TESTOBJECT_REINSTALL_APP = "testobject_reinstall_app";
	public static final String TESTOBJECT_REINSTALL_FRAMEWORK_APP = "testobject_reinstall_framework_app";
	public static final String TESTOBJECT_SESSION_CREATION_RETRY = "testobject_session_creation_retry";
	public static final String TESTOBJECT_SESSION_CREATION_TIMEOUT = "testobject_session_creation_timeout";
	public static final String TESTOBJECT_DEVICE_ALLOCATION_SLEEP_TIME = "testobject_device_session_sleep_time";
	public static final String TESTOBJECT_USER_ID = "testobject_user_id";
	public static final String TESTOBJECT_PROJECT_ID = "testobject_project_id";



	private TestObjectCapabilities() {
	}

	private static URL getURL(String url) {
		try {
			return new URL(url);
		} catch (MalformedURLException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}

	public static URL toTestObjectAppiumEndpointURL(URL baseURL) {
		try {
			return new URL("http", baseURL.getHost(), 80, "/wd/hub");
		} catch (MalformedURLException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}

	public static URL toTestObjectApiEndpointUrl(URL baseURL) {
		try {
			return new URL(baseURL.getProtocol(), baseURL.getHost(), baseURL.getPort(), "/api");
		} catch (MalformedURLException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}

}

@@ -175,36 +175,35 @@
  URL TESTOBJECT_
-BASE
+API
 _ENDPOINT = getU
@@ -217,19 +217,16 @@
 ps://app
-ium
 .testobj
@@ -236,16 +236,20 @@
 .com:443
+/api
 %22);%0A%09pub
@@ -274,33 +274,36 @@
 RL TESTOBJECT_AP
+P
 I
+UM
 _ENDPOINT = toTe
@@ -299,64 +299,380 @@
 OINT
- = toTestObjectApiEndpointUrl(TESTOBJECT_BASE_ENDPOINT);
+_US = getURL(%22https://us1.appium.testobject.com/wd/hub%22);%0A%09public static final URL TESTOBJECT_APPIUM_ENDPOINT_EU = getURL(%22https://eu1.appium.testobject.com/wd/hub%22);%0A%0A%09/**%0A%09 *%0A%09 * @deprecated Devices are now available in seperate US and EU data centers.%0A%09 *   Please use either TESTOBJECT_APPIUM_ENDPOINT_US or TESTOBJECT_APPIUM_ENDPOINT_EU accordingly.%0A%09 */%0A%09@Deprecated
 %0A%09pu
@@ -726,38 +726,8 @@
 T = 
-toTestObjectAppiumEndpointURL(
 TEST
@@ -737,12 +737,14 @@
 ECT_
-BASE
+APPIUM
 _END
@@ -748,17 +748,19 @@
 ENDPOINT
-)
+_EU
 ;%0A%0A%09publ
@@ -2758,488 +2758,6 @@
 %09%7D%0A%0A
-%09public static URL toTestObjectAppiumEndpointURL(URL baseURL) %7B%0A%09%09try %7B%0A%09%09%09return new URL(%22http%22, baseURL.getHost(), 80, %22/wd/hub%22);%0A%09%09%7D catch (MalformedURLException e) %7B%0A%09%09%09throw new RuntimeException(e.getMessage(), e);%0A%09%09%7D%0A%09%7D%0A%0A%09public static URL toTestObjectApiEndpointUrl(URL baseURL) %7B%0A%09%09try %7B%0A%09%09%09return new URL(baseURL.getProtocol(), baseURL.getHost(), baseURL.getPort(), %22/api%22);%0A%09%09%7D catch (MalformedURLException e) %7B%0A%09%09%09throw new RuntimeException(e.getMessage(), e);%0A%09%09%7D%0A%09%7D%0A%0A
 %7D%0A

Remove use of appium.testobject.com