package org.cru.godtools.s3;

import com.google.common.base.Strings;

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

/**
 * Created by ryancarlson on 7/11/15.
 */
public class AmazonS3GodToolsConfig
{
	public static final String BUCKET_NAME = "cru-godtools";

	private static final String BASE_URL = "https://s3.amazonaws.com/cru-godtools/";

	private static final String META = "meta/";
	private static final String PACKAGES = "packages/";
	private static final String TRANSLATIONS = "translations/";
	private static final String ALL_FILE = "all";
	private static final String XML = ".xml";
	private static final String ZIP = ".zip";

	public static String getMetaKeyV2()
	{
		return META + ALL_FILE + XML;
	}

	/**
	 * e.g. packages/en/all.zip  OR
	 */
	public static String getPackagesKeyV2(String languageCode)
	{
		return PACKAGES + languageCode + "/" + ALL_FILE + ZIP;
	}

	/**
	 * e.g. translations/en/all.zip  OR
	 */
	public static String getTranslationsKeyV2(String languageCode)
	{
		return TRANSLATIONS + languageCode + "/" + ALL_FILE + ZIP;
	}

	/**
	 * e.g. translations/en/kgp.zip
	 */
	public static String getTranslationsAndPackageKeyV2(String languageCode, String packageCode)
	{
		return TRANSLATIONS + languageCode + "/" + packageCode + ZIP;
	}

	public static URL getPackagesRedirectUrl(String languageCode) throws MalformedURLException
	{
		return getPackagesRedirectUrl(languageCode, null);
	}

	public static URL getPackagesRedirectUrl(String languageCode, String packageCode) throws MalformedURLException
	{
		if(Strings.isNullOrEmpty(packageCode))
		{
			return new URL(BASE_URL + PACKAGES + languageCode + "/" + ALL_FILE + ZIP);
		}
		else
		{
			return new URL(BASE_URL + PACKAGES + languageCode + "/" +  packageCode + ZIP);
		}
	}

	public static URL getMetaRedirectUrl() throws MalformedURLException
	{
		return new URL(BASE_URL + META + ALL_FILE + XML);
	}

	public static URL getTranslationsRedirectUrl(String languageCode) throws MalformedURLException
	{
		return getTranslationsRedirectUrl(languageCode, null);
	}

	public static URL getTranslationsRedirectUrl(String languageCode, String packageCode) throws MalformedURLException
	{
		if(Strings.isNullOrEmpty(packageCode))
		{
			return new URL(BASE_URL + TRANSLATIONS + languageCode + "/" + ALL_FILE + ZIP);
		}
		else
		{
			return new URL(BASE_URL + TRANSLATIONS + languageCode + "/" + packageCode + ZIP);
		}
	}
}

@@ -27,47 +27,8 @@
 3;%0A%0A
-import com.google.common.base.Strings;%0A
 %0Aimp
@@ -1342,49 +1342,73 @@
 urn 
-getPackagesRedirectUrl(languageCode, null
+new URL(BASE_URL + PACKAGES + languageCode + %22/%22 + ALL_FILE + ZIP
 );%0A%09
@@ -1529,147 +1529,8 @@
 %0A%09%7B%0A
-%09%09if(Strings.isNullOrEmpty(packageCode))%0A%09%09%7B%0A%09%09%09return new URL(BASE_URL + PACKAGES + languageCode + %22/%22 + ALL_FILE + ZIP);%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09
 %09%09re
@@ -1606,20 +1606,16 @@
 + ZIP);%0A
-%09%09%7D%0A
 %09%7D%0A%0A%09pub
@@ -1850,53 +1850,77 @@
 urn 
-getTranslationsRedirectUrl(languageCode, null
+new URL(BASE_URL + TRANSLATIONS + languageCode + %22/%22 + ALL_FILE + ZIP
 );%0A%09
@@ -2045,151 +2045,8 @@
 %0A%09%7B%0A
-%09%09if(Strings.isNullOrEmpty(packageCode))%0A%09%09%7B%0A%09%09%09return new URL(BASE_URL + TRANSLATIONS + languageCode + %22/%22 + ALL_FILE + ZIP);%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09
 %09%09re
@@ -2129,12 +2129,8 @@
 P);%0A
-%09%09%7D%0A
 %09%7D%0A%7D

Clean up methods