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

package com.ntels.onecable.common.broadcast;

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

/**
 * <pre>
 * 1. ClassName :   KneetMessageLocalBroadCast
 * 2. FileName  :   KneetMessageLocalBroadCast.java
 * 3. Package   :   com.ntels.onecable.common.gcm.support
 * 4. Date      :   2016-12-05
 * 5. Author    :   aaron
 * 6. Comment   :   Pooling & GCM 메시지 전달 로컬 브로드캐스트
 * </pre>
 */
public abstract class KneetMessageLocalBroadCast extends DefaultLocalBroadCast {
    /** Push 로컬 브로드캐스트 액션 명 */
    public final static String INTENT_ACTION = "Kneet.LocalBoradCast.App";

    /** 미지정 메시지 상태값 */
    public final static int INTENT_MSG_STATUS_NULL = -1;

    /** 미지정 메시지 타입 */
    public final static String INTENT_UNKOWN_MSG_TYPE = "INTENT_UNKOWN_MSG_TYPE";

    /** 중복 로그인 여부 */
    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);
    }

}
