package com.thebluealliance.androidclient.helpers;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.google.gson.JsonObject;
import com.thebluealliance.androidclient.R;
import com.thebluealliance.androidclient.types.WebcastType;

public class WebcastHelper {

    public static WebcastType getType(String typeString) {
        switch (typeString) {
            case "youtube":
                return WebcastType.YOUTUBE;
            case "twitch":
                return WebcastType.TWITCH;
            case "ustream":
                return WebcastType.USTREAM;
            case "livestream":
                return WebcastType.LIVESTREAM;
            case "iframe":
                return WebcastType.IFRAME;
            case "html5":
                return WebcastType.HTML5;
            case "stemtv":
                return WebcastType.STEMTV;
            default:
                return WebcastType.NONE;
        }
    }

    public static Intent getIntentForWebcast(Context context, String eventKey, WebcastType type, JsonObject params, int number) {
        switch (type) {
            case YOUTUBE:
                return getWebIntentForUrl(context.getString(R.string.webcast_youtube_embed_pattern, params.get("channel").getAsString()));
            case TWITCH:
                return getWebIntentForUrl(context.getString(R.string.webcast_twitch_embed_pattern, params.get("channel").getAsString()));
            case USTREAM:
                return getWebIntentForUrl(context.getString(R.string.webcast_ustream_embed_pattern, params.get("channel").getAsString()));
            case LIVESTREAM:
                return getWebIntentForUrl(context.getString(R.string.webcast_livestream_embed_pattern, params.get("channel").getAsString(), params.get("file").getAsString()));
            case HTML5:
                return new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.parse(params.get("channel").getAsString()), "video/*");
            case STEMTV:
                return new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.parse(context.getString(R.string.webcast_stemtv_embed_pattern, params.get("channel").getAsString())), "video/*");
            default:
            case IFRAME:
                return getWebIntentForUrl(context.getString(R.string.webcast_gameday_pattern, eventKey, number));
        }
    }

    public static Intent getWebIntentForUrl(String url) {
        return new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
    }

}

@@ -49,96 +49,8 @@
 s;%0A%0A
-import android.content.Context;%0Aimport android.content.Intent;%0Aimport android.net.Uri;%0A%0A
 impo
@@ -80,16 +80,17 @@
 Object;%0A
+%0A
 import c
@@ -186,16 +186,104 @@
 tType;%0A%0A
+import android.content.Context;%0Aimport android.content.Intent;%0Aimport android.net.Uri;%0A%0A
 public c
@@ -1098,24 +1098,167 @@
 t number) %7B%0A
+        if (type != WebcastType.IFRAME && !params.has(%22channel%22)) %7B%0A            return getGamedayIntent(context, eventKey, number);%0A        %7D%0A%0A
         swit
@@ -1783,32 +1783,165 @@
 ase LIVESTREAM:%0A
+                if (!params.has(%22file%22)) %7B%0A                    return getGamedayIntent(context, eventKey, number);%0A                %7D%0A
                 
@@ -2511,32 +2511,199 @@
 IFRAME:%0A        
+        return getGamedayIntent(context, eventKey, number);%0A        %7D%0A    %7D%0A%0A    public static Intent getGamedayIntent(Context context, String eventKey, int number) %7B%0A
         return g
@@ -2792,26 +2792,16 @@
 mber));%0A
-        %7D%0A
     %7D%0A%0A 

Add json checks to webcast intent builder