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

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

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

/**
 * <pre>
 * GCM 등록 ID 전달 로컬 브로드캐스트
 * </pre>
 *
 * @author Sangtae
 * @since 2014. 4. 11. 오전 10:57:28
 */
public abstract class GcmRegLocalBroadCast extends DefaultLocalBroadCast {
    /**
     * <pre>
     * GCM 등록 로컬 브로드캐스트 액션 명
     * </pre>
     *
     * @author Sangtae
     * @since 2014. 4. 10. 오후 8:42:51
     */
    public final static String INTENT_ACTION = "Kneet.LocalBoradCast.RegistrationID";

    public final static String INTENT_NAME_ACTION = "INTENT_NAME_ACTION";

    /**
     * <pre>
     * 메시지 상태값
     * </pre>
     *
     * @author Sangtae
     * @since 2014. 4. 10. 오후 9:14:12
     */
    public final static int INTENT_VALUE_NULL = -1;

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

        super.onReceive(context, intent);

        if ( intent.hasExtra(INTENT_NAME_ACTION) && intent.hasExtra(INTENT_NAME_RESULT_CODE) ) {
            onMessage(intent.getIntExtra(INTENT_NAME_ACTION, INTENT_VALUE_NULL), intent.getIntExtra(INTENT_NAME_RESULT_CODE, INTENT_VALUE_NULL), intent.getStringExtra(INTENT_NAME_MESSAGE));
        } else if ( intent.hasExtra(INTENT_NAME_RESULT_CODE) ) {
            onMessage(intent.getIntExtra(INTENT_NAME_RESULT_CODE, INTENT_VALUE_NULL), intent.getStringExtra(INTENT_NAME_MESSAGE));
        } else {
            onMessage(intent.getStringExtra(INTENT_NAME_MESSAGE));
        }
    }

    @Override
    public void onMessage(String msg) {

        super.onMessage(msg);
    }

    public void onMessage(int resultcode, String msg) {
        onMessage(msg);
    }

    public void onMessage(int action, int resultcode, String msg) {
        onMessage(msg);
        onMessage(resultcode, msg);
    }

}
