package cm.sip.hns;

import android.util.Log;

import java.util.StringTokenizer;

public class Forward {

    String TAG = "Forward";

    public boolean bForward;
    public int iForwardTarget; //0:세대기 1:경비실
    public String dong;
    public String ho;
    public String number;
    public String contact;

    boolean bLOG = true;   // true, false
    boolean bLOG_DEBUG = false;   // true, false
    boolean bLOG_INFO = true;   // true, false
    public Forward() {
        bForward = false;
        iForwardTarget = 0;
        dong = "";
        ho = "";
        number = "";
        contact = "";
    }

    private void LOG(String log) {
        if (bLOG) Log.v(TAG, log);
    }

    private void LOG_DEBUG(String log) {
        if (bLOG_DEBUG) Log.d(TAG, log);
    }

    private void LOG_INFO(String log) {
        if (bLOG_INFO) Log.i(TAG, log);
    }

    public void setValue(String value) {
        LOG("[setValue] value [" + value + "]");
        bForward = false;
        iForwardTarget = 0;
        dong = "";
        ho = "";
        number = "";
        contact = "";

        // parser
        StringTokenizer st = new StringTokenizer(value, ":", true);
        int tokenCount = 0;
        String token = null;
        boolean bMessage = false;
        String sender = "";
        try {
            while (st.hasMoreTokens()) {
                token = st.nextToken().trim();
                if (token != null && token.length() > 0 && token.compareTo(":") != 0) {
                    if (tokenCount == 0) {
                        if (token.compareTo("true") == 0) bForward = true;
                        else bForward = false;
                    } else if (tokenCount == 1) {
                        iForwardTarget = Integer.parseInt(token);
                        LOG_INFO("[setValue] FORWARD target : " + iForwardTarget);
                    } else if (tokenCount == 2) {
                        if (token.compareTo("null") == 0) dong = "";
                        else dong = token;
                    } else if (tokenCount == 3) {
                        if (token.compareTo("null") == 0) ho = "";
                        else ho = token;
                        break;
                    }
                    tokenCount++;
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] setValue(value) : " + e);
            e.printStackTrace();
        }
    }
}