package kr.co.icontrols.ilp300_700.imap;

import android.util.Log;

import kr.co.icontrols.ilp300_700.global.Configure.ConfigValue;
import kr.co.icontrols.ilp300_700.global.Configure.SetValue;
import kr.co.icontrols.ilp300_700.global.DataClasses.AccessKeyInfoTable;
import kr.co.icontrols.ilp300_700.global.DataClasses.ConfigValueTable;
import kr.co.icontrols.ilp300_700.global.DataClasses.LineInfoTable;
import kr.co.icontrols.ilp300_700.global.DataClasses.SystemUpgradeInfo;
import kr.co.icontrols.ilp300_700.global.Declare;
import kr.co.icontrols.ilp300_700.global.Declare.ServerVersion;
import kr.co.icontrols.ilp300_700.global.Global;

public class MakeiMAPMSG {

    public static String strSender = "";
    static String TAG = "MakeiMAPMSG";

    public static String makeHeader() {
        try {
            String strResult = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
                    "<imap ver=\"1.0\" address=\"" + ConfigValue.strDeviceIPAddress + "\" sender=\"" + strSender + "\">\r\n";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeHeader(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    // Notice message start

    public static String makeNotice_Heartbeat() {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"notice\" name=\"heartbeat\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <ver_moip>\"" + ConfigValue.strVer_MOIP + "\"</ver_moip>\r\n" +
                    "      <ver_bsp>\"" + ConfigValue.strVer_BSP + "\"</ver_bsp>\r\n" +
                    "      <ver_app>\"" + ConfigValue.strVer_APP + "\"</ver_app>\r\n" +
                    "      <ver_setting>\"" + ConfigValue.strVer_SETTING + "\"</ver_setting>\r\n" +
                    "      <ver_additional>\"" + ConfigValue.strVer_ADDITIONAL + "\"</ver_additional>\r\n" +
                    "      <ver_movie>\"" + ConfigValue.strVer_MOVIE + "\"</ver_movie>\r\n" +
                    "      <ver_moviesetting>\"" + ConfigValue.strVer_MOVIESETTING + "\"</ver_moviesetting>\r\n";

            if (ConfigValue.eMainServerType == SetValue.Server_Separated) {
                strResult += "      <ver_server>" + ServerVersion.strVer_1dot0 + "</ver_server>\r\n";
            } else if (ConfigValue.eMainServerType == SetValue.Server_Integrated) {
                strResult += "      <ver_server>" + ServerVersion.strVer_1dot5 + "</ver_server>\r\n";
            } else if (ConfigValue.eMainServerType == SetValue.Server2dot0_Integrated) {
                strResult += "      <ver_server>" + ServerVersion.strVer_2dot0 + "</ver_server>\r\n";
            }

            strResult += "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeNotice_Heartbeat(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeNotice_FTPUploadResult(String strUploadResult, String strFilePath, String strUploadPath, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"notice\" name=\"ftp_upload_result\">\r\n" +
                    "      <result>\"" + strUploadResult + "\"</result>\r\n" +
                    "      <filepath>\"" + strFilePath + "\"</filepath>\r\n" +
                    "      <uploadpath>\"" + strUploadPath + "\"</uploadpath>\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeNotice_FTPUploadResult(String strUploadResult, String strFilePath, String strUploadPath, String strMessage)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    // Notice message end


    // Request message start

    public static String makeRequest_ProposeUpgrade(SystemUpgradeInfo SysUpInfo) {
        try {
            String strResult = makeHeader() +
                    "   <service type=\"request\" name=\"propose_upgrade\">\r\n" +
                    "      <guidemap type=\"upgrade\" count=\"" + SysUpInfo.aModule_Type.length + "\" value=\"list\">\r\n";

            for (int i = 0; i < SysUpInfo.aModule_Type.length; i++) {
                strResult += "         <img module = \"" + SysUpInfo.aModule_Type[i] + "\" /> \r\n";
            }

            strResult += "      </guidemap>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_ProposeUpgrade()");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_device_bootup() {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"device_bootup\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <ver_moip>\"" + ConfigValue.strVer_MOIP + "\"</ver_moip>\r\n" +
                    "      <ver_bsp>\"" + ConfigValue.strVer_BSP + "\"</ver_bsp>\r\n" +
                    "      <ver_app>\"" + ConfigValue.strVer_APP + "\"</ver_app>\r\n" +
                    "      <ver_setting>\"" + ConfigValue.strVer_SETTING + "\"</ver_setting>\r\n";

            if (ConfigValue.eMainServerType == SetValue.Server_Separated) {
                strResult += "      <ver_server>" + ServerVersion.strVer_1dot0 + "</ver_server>\r\n";
            } else if (ConfigValue.eMainServerType == SetValue.Server_Integrated) {
                strResult += "      <ver_server>" + ServerVersion.strVer_1dot5 + "</ver_server>\r\n";
            } else if (ConfigValue.eMainServerType == SetValue.Server2dot0_Integrated) {
                strResult += "      <ver_server>" + ServerVersion.strVer_2dot0 + "</ver_server>\r\n";
            }

            strResult += "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_device_bootup(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_device_bootup_cnt(int nCnt) {
        try {
            // device_bootup.request 전송 횟수를 카운트하기 위한 함수
            String nTryCnt = Global.ZeroPadding_Head(4, Integer.toString(nCnt)) + ".00.00.00";
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"device_bootup\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <ver_moip>\"" + nTryCnt + "\"</ver_moip>\r\n" +
                    "      <ver_bsp>\"" + ConfigValue.strVer_BSP + "\"</ver_bsp>\r\n" +
                    "      <ver_app>\"" + ConfigValue.strVer_APP + "\"</ver_app>\r\n" +
                    "      <ver_setting>\"" + ConfigValue.strVer_SETTING + "\"</ver_setting>\r\n";

            if (ConfigValue.eMainServerType == SetValue.Server_Separated) {
                strResult += "      <ver_server>" + ServerVersion.strVer_1dot0 + "</ver_server>\r\n";
            } else if (ConfigValue.eMainServerType == SetValue.Server_Integrated) {
                strResult += "      <ver_server>" + ServerVersion.strVer_1dot5 + "</ver_server>\r\n";
            } else if (ConfigValue.eMainServerType == SetValue.Server2dot0_Integrated) {
                strResult += "      <ver_server>" + ServerVersion.strVer_2dot0 + "</ver_server>\r\n";
            }

            strResult += "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_device_bootup_cnt(nCnt)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_check_lobby_passwd(String strPW) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"check_lobby_passwd\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <inpasswd>" + strPW + "</inpasswd>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_check_lobby_passwd(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_check_sip_activation() {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"check_sip_activation\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <message>\"" + "null" + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_check_lobby_passwd(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_alarm_operation(String strMode, String strCause, String strDong, String strHo) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
//                    "   <service type=\"request\" name=\"alarm_operation\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n"+
                    "   <service type=\"request\" name=\"alarm_operation\">\r\n" +
                    "      <alarm_mode>\"" + strMode + "\"</alarm_mode>\r\n" +
                    "      <cause>\"" + strCause + "\"</cause>\r\n" +
                    "      <source dong=\"" + strDong + "\" ho=\"" + strHo + "\"/>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_alarm_operation(String strMode, String strCause, String strDong, String strHo)");
            e.printStackTrace();
            return "ERROR";
        }
    }
    //----------------------NYW--------------------------//

    //add 성공시 reply
    public static String makeReply_add_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable, String strDuplicate,String strTotal) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"reply\" name=\"add_facepic\" result=\"ok\">\r\n" +
                    "      <homeaddr dong=\"" + strDong + "\" ho=\"" + strHo + "\" alias=\"" + strAlias + "\"  />\r\n" +
                    "      <reason> \"" + strReason + "\" </reason>\r\n" +
                    "      <pics space=\"" + strSpace + "\" total=\"" + strTotal + "\" available=\"" + strAvailable + "\" Duplicate=\"" + strDuplicate + "\"/>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_add_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable, String strDuplicate,String strTotal)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    //del 성공시 reply
    public static String makeReply_del_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable,String strTotal) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"reply\" name=\"del_facepic\" result=\"ok\">\r\n" +
                    "      <homeaddr dong=\"" + strDong + "\" ho=\"" + strHo + "\" alias=\"" + strAlias + "\"  />\r\n" +
                    "      <reason> \"" + strReason + "\" </reason>\r\n" +
                    "      <pics space=\"" + strSpace + "\" total=\"" + strTotal + "\" available=\"" + strAvailable + "\"/>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_add_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable, String strDuplicate,String strTotal)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    //down 성공시 reply
    public static String makeReply_down_pic() {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"reply\" name=\"download_facepic\" result=\"ok\">\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_add_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable, String strDuplicate,String strTotal)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    //upgrade reply
    public static String Reply_upgrade_pic(String ret, String strReason) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"reply\" name=\"upgrade_facepic\" result=\""+ret+"\">\r\n" +
                    "      <reason> \"" + strReason + "\" </reason>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] failReply_add_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable, String strDuplicate,String strTotal)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    //add 실패시 reply
    public static String failReply_add_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable, String strDuplicate,String strTotal) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"reply\" name=\"add_facepic\" result=\"fail\">\r\n" +
                    "      <homeaddr dong=\"" + strDong + "\" ho=\"" + strHo + "\" alias=\"" + strAlias + "\"  />\r\n" +
                    "      <reason> \"" + strReason + "\" </reason>\r\n" +
                    "      <pics space=\"" + strSpace + "\" total=\"" + strTotal + "\" available=\"" + strAvailable + "\" available=\"" + strDuplicate + "\"/>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] failReply_add_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable, String strDuplicate,String strTotal)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    //down 실패시 reply
    public static String failReply_down_pic() {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"reply\" name=\"download_facepic\" result=\"fail\">\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] failReply_add_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable, String strDuplicate,String strTotal)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    //del 실패시 reply
    public static String failReply_del_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable,String strTotal) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"reply\" name=\"del_facepic\" result=\"fail\">\r\n" +
                    "      <homeaddr dong=\"" + strDong + "\" ho=\"" + strHo + "\" alias=\"" + strAlias + "\"  />\r\n" +
                    "      <reason> \"" + strReason + "\" </reason>\r\n" +
                    "      <pics space=\"" + strSpace + "\" total=\"" + strTotal + "\" available=\"" + strAvailable + "\" />\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] failReply_add_pic(String strReason, String strSpace, String strDong, String strHo, String strAlias,String strAvailable, String strDuplicate,String strTotal)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    // 출입이력 저장 성공시 reply
    public static String save_facepic_access(String strDong, String strHo, String strAlias,String strMethod, String strAceessResult, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"save_facepic_access\" result=\"ok\">\r\n" +
                    "   <homeaddr dong=\"" + strDong + "\" ho=\"" + strHo + "\" alias=\"" + strAlias + "\" method=\"" + strMethod + "\" result=\"" + strAceessResult + "\" message=\"" + strMessage + "\" />\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] save_facepic_access()");
            e.printStackTrace();
            return "ERROR";
        }
    }

    // 출입이력 저장 실패시 reply
    public static String fail_facepic_access() {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"reply\" name=\"add_facepic\" result=\"fail\">\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] fail_facepic_access()");
            e.printStackTrace();
            return "ERROR";
        }
    }

    //----------------------NYW--------------------------//


    public static String makeRequest_save_lobby_access(String strAction, String strTryby, String strWherefrom, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"save_lobby_access\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <action>\"" + strAction + "\"</action>\r\n" +
                    "      <tryby>\"" + strTryby + "\"</tryby>\r\n" +
                    "      <wherefrom>\"" + strWherefrom + "\"</wherefrom>\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_save_lobby_access(strAction, strTryby, strWherefrom, strMessage)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_save_lobby_access(String strAction, String strTryby, String strHomeAddrIP, int nHomeCardNo, int nHomeCardCount, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"save_lobby_access\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <action>\"" + strAction + "\"</action>\r\n" +
                    "      <tryby>\"" + strTryby + "\"</tryby>\r\n" +
                    "      <hcardinfo>\"" + strHomeAddrIP + "\"</hcardinfo>\r\n" +
                    "      <hnum>\"" + nHomeCardNo + "\"</hnum>\r\n" +
                    "      <hcount>\"" + nHomeCardCount + "\"</hcount>\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_save_lobby_access(strAction, strTryby, strHomeAddrIP, nHomeCardNo, nHomeCardCount, strMessage)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_save_lobby_access(String strAction, String strTryby, int nMasterCardNo, int nMasterCardCount, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"save_lobby_access\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <action>\"" + strAction + "\"</action>\r\n" +
                    "      <tryby>\"" + strTryby + "\"</tryby>\r\n" +
                    "      <mcardinfo>\"" + nMasterCardNo + "\"</mcardinfo>\r\n" +
                    "      <mcount>\"" + nMasterCardCount + "\"</mcount>\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_save_lobby_access(strAction, strTryby, nMasterCardNo, nMasterCardCount, strMessage");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_save_lobby_access(String strAction, String strTryby, String strRecogResult, String strRecogReason, String strOwnerID, String strOwnerName, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"save_lobby_access\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <action>\"" + strAction + "\"</action>\r\n" +
                    "      <tryby>\"" + strTryby + "\"</tryby>\r\n" +
                    "      <recog_info result=\"" + strRecogResult + "\" reason=\"" + strRecogReason + "\"/>\r\n" +
                    "      <owner_info id=\"" + strOwnerID + "\" name=\"" + strOwnerName + "\"/>\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_save_lobby_access(String strAction, String strTryby, String strRecogResult, String strRecogReason, String strOwnerID, String strOwnerName, String strMessage)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_save_vcard_access(String strAction, String strDistinct, String strDong, String strHo, int nVCardNo, int nVCardCnt, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"save_vcard_access\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <action>\"" + strAction + "\"</action>\r\n" +
                    "      <vcardinfo distinct=\"" + strDistinct + "\" id_high=\"" + strDong + "\" id_low=\"" + strHo + "\" vnum=\"" + nVCardNo + "\" vcount=\"" + nVCardCnt + "\">\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_save_vcard_access(Info)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_save_uidcard_access(String strAction, String strDistinct, String strID_High, String strID_Low, String strCardType, String strSN, String strUID, String strMessage) {
        try {
            String distinct = "NONE";
            if (strDistinct.equals("hkey")) distinct = "hcard";
            else if (strDistinct.equals("dkey")) distinct = "dcard";
            else if (strDistinct.equals("mkey")) distinct = "mcard";

            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"save_uidcard_access\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <action>\"" + strAction + "\"</action>\r\n" +
                    "      <uidcard_info distinct=\"" + distinct + "\" id_high=\"" + strID_High + "\" id_low=\"" + strID_Low + "\" card_type=\"" + strCardType + "\" sn=\"" + strSN + "\" uid=\"" + strUID + "\"/>\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_save_uidcard_access(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_lobby_sync_cardinfo(String strResiIP, int nIssueCnt) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"lobby_sync_cardinfo\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <home_addr>\"" + strResiIP + "\"</home_addr>\r\n" +
                    "      <card_gen_cnt>\"" + nIssueCnt + "\"</card_gen_cnt>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_lobby_sync_cardinfo(strResiIP, nIssueCnt");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_lobby_sync_dcardinfo(int nIDNo, int nIssueCnt) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"lobby_sync_dcardinfo\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <card_number>\"" + nIDNo + "\"</card_number>\r\n" +
                    "      <card_gen_cnt>\"" + nIssueCnt + "\"</card_gen_cnt>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_lobby_sync_dcardinfo(nIDNo, nIssueCnt");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_lobby_sync_mcardinfo(int nIDNo, int nIssueCnt) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"lobby_sync_mcardinfo\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <card_number>\"" + nIDNo + "\"</card_number>\r\n" +
                    "      <card_gen_cnt>\"" + nIssueCnt + "\"</card_gen_cnt>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_lobby_sync_mcardinfo(nIDNo, nIssueCnt");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_event_notify(String strEvent) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"event_notify\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <event>\"" + strEvent + "\"</event>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_check_lobby_passwd(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_elevator_call(String strDong, String strHo, String strCMD) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"elevator_call\" dev_type=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\">\r\n" +
                    "      <home_info dong=\"" + strDong + "\" ho=\"" + strHo + "\"/>\r\n" +
                    "      <call_info>\"" + strCMD + "\"</call_info>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_alarm_operation(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_get_setup_info(ConfigValueTable GetSetupInfoValue) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            int nCnt = GetSetupInfoValue.getCnt();
            strResult += "   <service type=\"request\" name=\"get_setup_info\">\r\n" +
                    "      <guidemap devtype=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\" count=\"" + nCnt + "\">\r\n";
            for (int i = 0; i < nCnt; i++) {
                strResult += "         <variable>\"" + GetSetupInfoValue.getConfigValue(i).NAME() + "\"</variable>\r\n";
            }
            strResult += "      </guidemap>\r\n";
            strResult += "   </service>\r\n";
            strResult += "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_get_setup_info(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_check_call_option() {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"check_call_option\">\r\n" +
                    "      <message>\"null\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_check_call_option()");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_chat_sequence(String strSeq, String strStatus) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"chat_sequence\">\r\n" +
                    "      <sequence>\"" + strSeq + "\"</sequence>\r\n" +
                    "      <status>\"" + strStatus + "\"</status>\r\n" +
                    "      <message>\"null\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_chat_sequence()");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_chat_message(String strChat) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"chat_message\">\r\n" +
                    "      <chat>\"" + strChat + "\"</chat>\r\n" +
                    "      <message>\"null\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_chat_message(String strChat)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_verify_access_authorization(String strDevice, String strID, String strRecogType, String strOwner, int nDataLength, String strRecogData, String strMessage) {
        try {
            // strRecogData.replaceAll("\\n", "") : 개행문자 삭제를 위해 사용한다. (개행문자가 자동으로 삽입됨)
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"verify_access_authorization\">\r\n" +
                    "      <source device=\"" + strDevice + "\" id=\"" + strID + "\"/>\r\n" +
                    "      <recog_info type=\"" + strRecogType + "\" owner=\"" + strOwner + "\" length=\"" + nDataLength + "\"/>\r\n" +
                    "      <recog_data>\"" + strRecogData.replaceAll("\\n", "") + "\"</recog_data>\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_verify_access_authorization(String strDevice, String strID, String strRecogType, String strOwner, int nDataLength, String strRecogData, String strMessage)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeRequest_get_accesskey_info_UID(String strUID, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader() +
                    "   <service type=\"request\" name=\"get_accesskey_info\">\r\n"+
                    "      <info_type>\"uid\"</info_type>\r\n" +
                    "      <uid_info>\"" + strUID + "\"</uid_info>\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeRequest_get_accesskey_info_UID(String strUID, String strMessage)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    // Request message end


    // Reply message start

    public static String makeReply_upgrade(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"upgrade\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"upgrade\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_upgrade(boolean bResult)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_set_server_version(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"set_server_version\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"set_server_version\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_check_sip_activation(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_lobby_open(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"lobby_open\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"lobby_open\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_lobby_open(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_lobby_door_ctrl(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"lobby_door_ctrl\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"lobby_door_ctrl\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_lobby_door_ctrl(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_device_reset(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"device_reset\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"device_reset\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_device_reset(boolean bResult)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_set_setup_info(boolean bResult, String strFirstFailed) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"set_setup_info\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                if (strFirstFailed != null) {
                    strResult += "   <service type=\"reply\" name=\"set_setup_info\" result=\"fail\">\r\n" +
                            "      <first_failed>\"" + strFirstFailed + "\"</first_failed>\r\n";
                } else {
                    strResult += "   <service type=\"reply\" name=\"set_setup_info\" result=\"fail\"/>\r\n";
                }
                strResult += "   </service>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_set_setup_info(boolean bResult, String strFirstFailed)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_get_setup_info(boolean bResult, String strFirstFailed, ConfigValueTable GetSetupInfoValue, int[] iData) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                int nCnt = GetSetupInfoValue.getCnt();
                strResult += "   <service type=\"reply\" name=\"get_setup_info\" result=\"ok\">\r\n" +
                        "      <guidemap devtype=\"" + Declare.DeviceInfo.Type.toString().toLowerCase() + "\" count=\"" + nCnt + "\">\r\n";
                for (int i = 0; i < nCnt; i++) {
                    if (GetSetupInfoValue.getConfigValue(i).NAME().equalsIgnoreCase("line_info")) {
                        LineInfoTable mLineInfoTable = new LineInfoTable();
                        int nLineCnt = Integer.parseInt(GetSetupInfoValue.getConfigValue(i).CNT());
                        mLineInfoTable = (LineInfoTable) GetSetupInfoValue.getConfigValue(i).LIST();
                        if (nLineCnt != mLineInfoTable.getCnt()) continue;
                        strResult += "         <setting name=\"" + GetSetupInfoValue.getConfigValue(i).NAME() + "\" count=\"" + nLineCnt + "\" value=\"list\">\r\n";
                        for (int j = 0; j < nLineCnt; j++) {
                            strResult += "            <list name=\"" + mLineInfoTable.getLineInfo(j).NAME() + "\" value=\"" + mLineInfoTable.getLineInfo(j).LOW() + "-" + mLineInfoTable.getLineInfo(j).HIGH() + "\"/>\r\n";
                        }
                        strResult += "         </setting>\r\n";
                    } else {
                        strResult += "         <setting name=\"" + GetSetupInfoValue.getConfigValue(i).NAME() + "\" count=\"0\" value=\"" + GetSetupInfoValue.getConfigValue(i).VALUE() + "\"/>\r\n";
                    }
                }

                String[] strDataName = {"facerecog_level", "facerecog_ai", "facerecog_mask", "facerecog_thres_level"};
                for (int i = 0; i < iData.length; i++) {
                    if(iData[i] != 0)
                        if((i == 1) || (i ==2))
                        {
                            if(iData[i] == 1) strResult += "         <setting name=\"" + strDataName[i] + "\" count=\"0\" value=\"" + "disable" + "\"/>\r\n";
                            else if(iData[i] == 2) strResult += "         <setting name=\"" + strDataName[i] + "\" count=\"0\" value=\"" + "enable" + "\"/>\r\n";
                        }
                        else
                            strResult += "         <setting name=\"" + strDataName[i] + "\" count=\"0\" value=\"" + iData[i] + "\"/>\r\n";
                }

                strResult += "      </guidemap>\r\n";
                strResult += "   </service>\r\n";
                strResult += "</imap>";
            } else {
                if (strFirstFailed != null) {
                    strResult += "   <service type=\"reply\" name=\"get_setup_info\" result=\"fail\">\r\n"
                            + "      <first_failed>\"" + strFirstFailed + "\"</first_failed>\r\n";
                } else {
                    strResult += "   <service type=\"reply\" name=\"get_setup_info\" result=\"fail\"/>\r\n";
                }
                strResult += "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_get_setup_info(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_set_accesskey_info(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"set_accesskey_info\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"set_accesskey_info\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_set_accesskey_info(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_get_accesskey_info(boolean bResult, AccessKeyInfoTable KeyInfoTable) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();

            if (!bResult) {
                strResult += "   <service type=\"reply\" name=\"get_accesskey_info\" result=\"fail\"/>\r\n" +
                        "</imap>";

                return strResult;
            }

            if (KeyInfoTable == null) {
                strResult += "   <service type=\"reply\" name=\"get_accesskey_info\" result=\"fail\"/>\r\n" +
                        "</imap>";

                return strResult;
            }

            int nCnt = KeyInfoTable.getCnt();

            if (nCnt == 0) {
                strResult += "   <service type=\"reply\" name=\"get_accesskey_info\" result=\"fail\"/>\r\n" +
                        "</imap>";

                return strResult;
            }

            if (nCnt == 1 && KeyInfoTable.getKeyInfo(0).getUID().equalsIgnoreCase("NONE")) {
                strResult += "   <service type=\"reply\" name=\"get_accesskey_info\" result=\"none\"/>\r\n" +
                        "</imap>";

                return strResult;
            } else if (nCnt == 1 && KeyInfoTable.getKeyInfo(0).getUID().equalsIgnoreCase("DUPLICATED")) {
                strResult += "   <service type=\"reply\" name=\"get_accesskey_info\" result=\"duplicated\"/>\r\n" +
                        "</imap>";

                return strResult;
            }


            // 검색 성공, 키정보 전송
            strResult += "   <service type=\"reply\" name=\"get_accesskey_info\" result=\"ok\"/>\r\n" +
                    "      <key_type>\"" + KeyInfoTable.getKeyInfo(0).getType() + "\"</key_type>\r\n";

            if (KeyInfoTable.getKeyInfo(0).getType().equals("hkey")) {
                strResult += "      <hkey_info dong=\"" + KeyInfoTable.getKeyInfo(0).getDong() + "\" ho=\"" + KeyInfoTable.getKeyInfo(0).getHo() + "\" count=\"" + nCnt + "\"/>\r\n";
            } else if (KeyInfoTable.getKeyInfo(0).getType().equals("dkey")) {
                strResult += "      <dkey_info dong=\"" + KeyInfoTable.getKeyInfo(0).getDong() + "\" count=\"" + nCnt + "\"/>\r\n";
            } else if (KeyInfoTable.getKeyInfo(0).getType().equals("mkey")) {
                strResult += "      <mkey_info count=\"" + nCnt + "\"/>\r\n";
            }

            int nIndex = 0;
            for (int i = 0; i < nCnt; i++) {
                nIndex = i + 1;
                strResult += "      <key_info index=\"" + nIndex + "\" sn=\"" + KeyInfoTable.getKeyInfo(i).getSN() + "\" uid=\"" + KeyInfoTable.getKeyInfo(i).getUID() + "\" key_num=\"" + KeyInfoTable.getKeyInfo(i).getKeyNo() +
                        "\" issue_cnt=\"" + KeyInfoTable.getKeyInfo(i).getIssueCnt() + "\" issued_date=\"" + KeyInfoTable.getKeyInfo(i).getIssuedDate() + "\" message=\"" + KeyInfoTable.getKeyInfo(i).getMessage() + "\"/>\r\n";
            }

            strResult += "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_get_accesskey_info(boolean bResult, AccessKeyInfoTable KeyInfoTable)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_set_keyinfo_cham(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"set_keyinfo_cham\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"set_keyinfo_cham\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_set_keyinfo_cham(boolean bResult)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_get_keyinfo_cham(boolean bResult, AccessKeyInfoTable KeyInfoTable) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();

            if (!bResult) {
                strResult += "   <service type=\"reply\" name=\"get_keyinfo_cham\" result=\"fail\"/>\r\n" +
                        "</imap>";

                return strResult;
            }

            int nCnt = KeyInfoTable.getCnt();
            if (KeyInfoTable == null || nCnt == 0) {
                strResult += "   <service type=\"reply\" name=\"get_keyinfo_cham\" result=\"fail\"/>\r\n" +
                        "</imap>";

                return strResult;
            }

            if (nCnt == 1 && KeyInfoTable.getKeyInfo(0).getUID().equalsIgnoreCase("NONE")) {
                strResult += "   <service type=\"reply\" name=\"get_keyinfo_cham\" result=\"none\"/>\r\n" +
                        "</imap>";

                return strResult;
            } else if (nCnt == 1 && KeyInfoTable.getKeyInfo(0).getUID().equalsIgnoreCase("DUPLICATED")) {
                strResult += "   <service type=\"reply\" name=\"get_keyinfo_cham\" result=\"duplicated\"/>\r\n" +
                        "</imap>";

                return strResult;
            }


            // 검색 성공, 키정보 전송
            strResult += "   <service type=\"reply\" name=\"get_keyinfo_cham\" result=\"ok\"/>\r\n";

            if (KeyInfoTable.getKeyInfo(0).getType().equals("hkey")) {
                strResult += "      <key_type>\"hcard\"</key_type>\r\n" +
                        "      <hcard_info dong=\"" + KeyInfoTable.getKeyInfo(0).getDong() + "\" ho=\"" + KeyInfoTable.getKeyInfo(0).getHo() + "\" count=\"" + nCnt + "\"/>\r\n";
            } else if (KeyInfoTable.getKeyInfo(0).getType().equals("dkey")) {
                strResult += "      <key_type>\"dcard\"</key_type>\r\n" +
                        "      <dcard_info dong=\"" + KeyInfoTable.getKeyInfo(0).getDong() + "\" count=\"" + nCnt + "\"/>\r\n";
            } else if (KeyInfoTable.getKeyInfo(0).getType().equals("mkey")) {
                strResult += "      <key_type>\"mcard\"</key_type>\r\n" +
                        "      <mcard_info count=\"" + nCnt + "\"/>\r\n";
            }

            int nIndex = 0;
            for (int i = 0; i < nCnt; i++) {
                nIndex = i + 1;
                strResult += "      <key_info index=\"" + nIndex + "\" sn=\"" + KeyInfoTable.getKeyInfo(i).getSN() + "\" uid=\"" + KeyInfoTable.getKeyInfo(i).getUID() +
                        "\" cardid=\"" + KeyInfoTable.getKeyInfo(i).getKeyNo() + "\" message=\"" + KeyInfoTable.getKeyInfo(i).getMessage() + "\"/>\r\n";
            }

            strResult += "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_get_keyinfo_cham(boolean bResult, AccessKeyInfoTable KeyInfoTable)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_cardrd_sync_cardinfo(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"cardrd_sync_cardinfo\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"cardrd_sync_cardinfo\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_cardrd_sync_cardinfo(boolean bResult)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_check_sip_activation(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"check_sip_activation\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"check_sip_activation\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_check_sip_activation(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_lobby_sync_cardinfo(boolean bResult, String strResiIP, int nIssueCnt) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult)
                strResult += "   <service type=\"reply\" name=\"lobby_sync_cardinfo\" result=\"ok\"/>\r\n";
            else
                strResult += "   <service type=\"reply\" name=\"lobby_sync_cardinfo\" result=\"fail\">\r\n";
            strResult += "      <home_addr>\"" + strResiIP + "\"</home_addr>\r\n" +
                    "      <card_gen_cnt>\"" + nIssueCnt + "\"</card_gen_cnt>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_lobby_sync_cardinfo(strResiIP, nIssueCnt");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_lobby_sync_dcardinfo(boolean bResult, int nIDNo, int nIssueCnt) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult)
                strResult += "   <service type=\"reply\" name=\"lobby_sync_dcardinfo\" result=\"ok\"/>\r\n";
            else
                strResult += "   <service type=\"reply\" name=\"lobby_sync_dcardinfo\" result=\"fail\">\r\n";
            strResult += "      <card_number>\"" + nIDNo + "\"</card_number>\r\n" +
                    "      <card_gen_cnt>\"" + nIssueCnt + "\"</card_gen_cnt>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_lobby_sync_dcardinfo(nIDNo, nIssueCnt");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_lobby_sync_mcardinfo(boolean bResult, int nIDNo, int nIssueCnt) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult)
                strResult += "   <service type=\"reply\" name=\"lobby_sync_mcardinfo\" result=\"ok\"/>\r\n";
            else
                strResult += "   <service type=\"reply\" name=\"lobby_sync_mcardinfo\" result=\"fail\">\r\n";
            strResult += "      <card_number>\"" + nIDNo + "\"</card_number>\r\n" +
                    "      <card_gen_cnt>\"" + nIssueCnt + "\"</card_gen_cnt>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_lobby_sync_mcardinfo(nIDNo, nIssueCnt");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_check_call_option(boolean bResult, String strOption) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"check_call_option\" result=\"ok\">\r\n";
            } else {
                strResult += "   <service type=\"reply\" name=\"check_call_option\" result=\"fail\">\r\n";
            }
            strResult += "      <option>\"" + strOption + "\"</option>\r\n" +
                    "      <message>\"null\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_check_call_option(boolean bResult, String strOption)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_chat_sequence(boolean bResult, String strFrom, String strTo, String strContact, String strSeq, String strStatus, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"chat_sequence\" result=\"ok\">\r\n";
            } else {
                strResult += "   <service type=\"reply\" name=\"chat_sequence\" result=\"fail\">\r\n";
            }
            strResult += "      <from>\"" + strFrom + "\"</from>\r\n" +
                    "      <to>\"" + strTo + "\"</to>\r\n" +
                    "      <contact>\"" + strContact + "\"</contact>\r\n" +
                    "      <sequence>\"" + strSeq + "\"</sequence>\r\n" +
                    "      <status>\"" + strStatus + "\"</status>\r\n" +
                    "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_chat_sequence(boolean bResult, String strFrom, String strTo, String strContact, String strSeq, String strStatus, String strMessage)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_chat_message(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"chat_message\" result=\"ok\">\r\n";
            } else {
                strResult += "   <service type=\"reply\" name=\"chat_message\" result=\"fail\">\r\n";
            }
            strResult += "      <message>\"null\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";


            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_chat_message(boolean bResult)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_ftp_upload(boolean bResult, String strMessage) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"ftp_upload\" result=\"ok\">\r\n";
            } else {
                strResult += "   <service type=\"reply\" name=\"ftp_upload\" result=\"fail\">\r\n";
            }
            strResult += "      <message>\"" + strMessage + "\"</message>\r\n" +
                    "   </service>\r\n" +
                    "</imap>";


            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_ftp_upload(boolean bResult, String strMessage)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_lobby_open_onepass(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"lobby_open_onepass\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"lobby_open_onepass\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_lobby_open_onepass(boolean bResult)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_remote_debug_connect(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"remote_debug_connect\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"remote_debug_connect\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_remote_debug_connect(boolean bResult)");
            e.printStackTrace();
            return "ERROR";
        }
    }

    public static String makeReply_device_live_check(boolean bResult) {
        try {
            String strResult = MakeiMAPMSG.makeHeader();
            if (bResult) {
                strResult += "   <service type=\"reply\" name=\"device_live_check\" result=\"ok\"/>\r\n" +
                        "</imap>";
            } else {
                strResult += "   <service type=\"reply\" name=\"device_live_check\" result=\"fail\"/>\r\n" +
                        "</imap>";
            }

            return strResult;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] makeReply_device_live_check(...)");
            e.printStackTrace();
            return "ERROR";
        }
    }


    // Reply message end


}