/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

package com.ntels.kneet.v3.common.gcm.support;

import android.content.Context;
import android.content.Intent;

/**
 * <pre>
 * Pooling & GCM 메시지 전달 로컬 브로드캐스트
 * </pre>
 *
 * @author Sangtae
 * @since 2014. 4. 11. 오전 10:57:28
 */
public abstract class KneetMessageLocalBroadCast extends DefaultLocalBroadCast {
    /**
     * <pre>
     * Push 로컬 브로드캐스트 액션 명
     * </pre>
     *
     * @author Sangtae
     * @since 2014. 4. 10. 오후 8:42:51
     */
    public final static String INTENT_ACTION = "Kneet.LocalBoradCast.App";

    /**
     * <pre>
     * 미지정 메시지 상태값
     * </pre>
     *
     * @author Sangtae
     * @since 2014. 4. 10. 오후 9:14:12
     */
    public final static int    INTENT_MSG_STATUS_NULL = -1;
    /**
     * <pre>
     * 미지정 메시지 타입
     * </pre>
     *
     * @author Sangtae
     * @since 2014. 4. 11. 오전 11:12:29
     */
    public final static String INTENT_UNKOWN_MSG_TYPE = "INTENT_UNKOWN_MSG_TYPE";

    /**
     * <pre>
     * 중복 로그인 여부
     * </pre>
     *
     * @author Sangtae
     * @since 2014. 5. 15. 오후 3:41:01
     */
    public final static String INTENT_DUPLICATE_LOGIN = "INTENT_DUPLICATE_LOGIN";
    public final static String INTENT_ACTION_APP_EXIT = "INTENT_ACTION_APP_EXIT";
    public final static String INTENT_ACTION_HOMEHUB_STATE_CHANGE = "INTENT_ACTION_HOMEHUB_STATE_CHANGE";

    @Override
    public void onReceive(Context context, Intent intent) {

        super.onReceive(context, intent);

        if ( intent.hasExtra(INTENT_DUPLICATE_LOGIN) ) {
            onMessage(intent.getStringExtra(INTENT_NAME_TYPE), intent.getStringExtra(INTENT_NAME_MESSAGE), intent.getBooleanExtra(INTENT_DUPLICATE_LOGIN, false));
        } else if ( intent.hasExtra(INTENT_ACTION_APP_EXIT) ) {
            onMessage(intent.getStringExtra(INTENT_NAME_TYPE), intent.getStringExtra(INTENT_NAME_MESSAGE), intent.getBooleanExtra(INTENT_ACTION_APP_EXIT, false));
        } else if ( intent.hasExtra(INTENT_ACTION_HOMEHUB_STATE_CHANGE) ) {
            onMessage(intent.getStringExtra(INTENT_NAME_TYPE), intent.getStringExtra(INTENT_NAME_MESSAGE), intent.getBooleanExtra(INTENT_ACTION_HOMEHUB_STATE_CHANGE, false));
        } else if ( intent.hasExtra(INTENT_NAME_TYPE) ) {
            onMessage(intent.getStringExtra(INTENT_NAME_TYPE), intent.getStringExtra(INTENT_NAME_MESSAGE));
        } else {
            onMessage(intent.getStringExtra(INTENT_NAME_MESSAGE));
        }
    }

    @Override
    public void onMessage(String msg) {

        super.onMessage(msg);
    }

    public void onMessage(String messageType, String msg) {
        onMessage(msg);
    }

    public void onMessage(String messageType, String msg, Boolean bVal) {
        onMessage(msg);
        onMessage(messageType, msg);
    }

}
