package com.dbs.mplus.fatima.util;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.dbs.mplus.fatima.MPlusConstants;
import com.dbs.mplus.fatima.framework.MPlusFrameworkConstants;
import com.dbs.mplus.fatima.framework.util.MPlusIntentUtil;
import com.dbs.mplus.fatima.service.DeviceTokenPrepareService;
import com.dbs.mplus.fatima.view.popup.MPlusNotifyPopupActivity;
import com.dbs.mplus.fatima.view.popup.MPlusWebAuthPopupActivity;
import com.dbs.mplus.fatima.view.popup.MPlusWebExtraPopupActivity;
import com.dbs.mplus.fatima.view.web.MPlusWebActivity;

/**
 * 천지사방에 Intent가 널려있는것을 방지하기 위한 유틸 
 * Intent는 여기에서만 만들어 사용한다. 
 * 
 * @author aple
 *
 */
public class IntentUtil extends MPlusIntentUtil {
	private static final int INTENT_FLAG = Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP;
	

	/**
	 * 시작주소로 브라우징 
	 * @param appContext
	 * @return
	 */
	public static Intent getBrowsingIntent(Context appContext) { 
        return MPlusIntentUtil.getDefaultBrowsingIntent(appContext, MPlusWebActivity.class, AddrUtil.getStartPage());
	}
	
	/**
	 * 지정 주소로 브라우징 
	 * @param context
	 * @param url
	 * @return
	 */
	public static Intent getBrowsingIntent(Context context, String url) { 
		return MPlusIntentUtil.getBrowsingIntent(context, MPlusWebActivity.class, url);
	}
	
	/**
	 * device token 확인 서비스 
	 * 
	 * @param activity
	 * @return
	 */
	public static Intent getDeviceTokenPrepareIntentService(Activity activity) { 
		return new Intent(activity, DeviceTokenPrepareService.class); 
	}
	
	/**
	 * device token 준비 결과 
	 * @param success 
	 * @return
	 */
	public static Intent getDeviceTokenPrepareComplete(boolean success) { 
		final Intent intent = new Intent(MPlusConstants.ACTION_TOKEN_PREPARE);
		intent.putExtra(MPlusConstants.PARAM_TOKEN_PREPARE_COMPLETE_STR, success);
		
		return intent; 
	}
	/**
	 * 버전확인시작하라고 알림 
	 * @return
	 */
	public static Intent getVersionCheckIntent() { 
		return new Intent(MPlusConstants.ACTION_VERSION_CHECK);
	}

	/**
	 * 화면에 팝업창 
	 * @param context
	 * @param action 
	 * @param b
	 * @return
	 */
	public static Intent getNotifyIntent(Context context, String action, Bundle b) { 
		final Intent wakeIntent = new Intent(context, MPlusNotifyPopupActivity.class);
		
		if(action != null) { 
			wakeIntent.setAction(action); 
		}
		
		wakeIntent.setFlags(IntentUtil.INTENT_FLAG | Intent.FLAG_ACTIVITY_NEW_TASK);
		wakeIntent.putExtras(b);	
		
		return wakeIntent; 
	}

	/**
	 * 화면에 팝업창 
	 * @param context
	 * @param action
	 * @param key
	 * @param value
	 * @return
	 */
	public static Intent getNotifyIntent(Context context, String action, String key, String value) { 
		final Bundle bundle = new Bundle(); 
		if(key != null && value != null) { 	
			bundle.putString(key, value);
		}
		
		return IntentUtil.getNotifyIntent(context, action, bundle); 		
	}
	
	
	/**
	 * 사용자 인증을 위한 팝업창 띄워서 브라우징
	 * @param activity
	 * @param url
	 * @return
	 */
	public static Intent getAuthPopupBrowsingIntent(Activity activity, String url) {
		final Intent intent = new Intent(activity, MPlusWebAuthPopupActivity.class);
		// 살리고 위에 올라가야함 
		intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); 
		// 파라미터들 
		intent.putExtra(MPlusFrameworkConstants.ACTION_KEY, MPlusFrameworkConstants.ACTION_AUTH_POPUP_BROWSING);
		intent.putExtra(MPlusFrameworkConstants.MSG_VALUE_KEY.BROWSING_URL.toString(), url);

		return intent;
	}

	/**
	 * 일반 브라우징을 위한 팝업창 띄워서 브라우징
	 * @param activity
	 * @param url
	 * @return
	 */
	public static Intent getExtraPopupBrowsingIntent(Activity activity, String url) {
		final Intent intent = new Intent(activity, MPlusWebExtraPopupActivity.class);
		// 살리고 위에 올라가야함
		intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
		// 파라미터들
		intent.putExtra(MPlusFrameworkConstants.ACTION_KEY, MPlusFrameworkConstants.ACTION_EXTRA_POPUP_BROWSING);
		intent.putExtra(MPlusFrameworkConstants.MSG_VALUE_KEY.BROWSING_URL.toString(), url);

		return intent;
	}
}
