package kr.co.icontrols.ilp300_700.imap;

import android.content.Context;
import android.util.Log;

import java.net.Socket;

import kr.co.icontrols.ilp300_700.ethernet.SendNWaitMSG;
import kr.co.icontrols.ilp300_700.ethernet.iMAPCommon;
import kr.co.icontrols.ilp300_700.ethernet.iMAPServer;
import kr.co.icontrols.ilp300_700.global.Configure;

public class reply_add_facepic extends SendNWaitMSG {

    String TAG = "Request_alarm_operation";

    boolean bLOG = true;   // true, false
    boolean bLOG_DEBUG = false;   // true, false
    boolean bLOG_INFO = true;   // true, false
    Context mContext;
    iMAPCommon.iMAPResult miMAPResult;
    iMAPResultCtrl miMAPResultCtrl;
    int nNonEncryptedTargetPort = 10000;
    int nEncryptedTargetPort = 11000;
    int nTargetPort = nNonEncryptedTargetPort;
    public reply_add_facepic(Context context) {
        LOG_INFO("[Request_alarm_operation] === START ===");
        mContext = context;
        if (Configure.ConfigValue.eMainServerType == Configure.SetValue.Server2dot0_Integrated)
            nTargetPort = nEncryptedTargetPort;
    }

    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);
    }


    //add 성공시
    public boolean send_add_pic_reply(Socket Sock, String strTargetIP, String strReason, String strSpace, String strDong, String strHo,String strAlias,String strAvailable,String strDuplicate,String strTotal) {
        try {
            LOG_INFO("[send_alarm_operation_request] strTargetIP [" + strTargetIP + "], strReason [" + strReason + "], strSpace [" + strSpace + "], strDong [" + strDong + "], strHo [" + strHo + "]");
            LOG_INFO("[send_alarm_operation_request] strAlias [" + strAlias + "], strAvailable [\"null\"], strDuplicate [\"null\"], strTotal [\"null\"]");
            return iMAPServer.sendReply(Sock, MakeiMAPMSG.makeReply_add_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable, strDuplicate, strTotal));
            //return sendNwaitMSG(strTargetIP, nTargetPort, MakeiMAPMSG.makeReply_add_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable, strDuplicate, strTotal));
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_alarm_operation_request(strTargetIP, strMode, strCause, strDong, strHo)");
            e.printStackTrace();
            return false;
        }
    }

    //del 성공시
    public boolean send_del_pic_reply(Socket Sock, String strTargetIP, String strReason, String strSpace, String strDong, String strHo,String strAlias,String strAvailable,String strTotal) {
        try {
            LOG_INFO("[send_alarm_operation_request] strTargetIP [" + strTargetIP + "], strReason [" + strReason + "], strSpace [" + strSpace + "], strDong [" + strDong + "], strHo [" + strHo + "]");
            LOG_INFO("[send_alarm_operation_request] strAlias [" + strAlias + "], strAvailable [" + strAvailable + "], strTotal [" + strTotal + "]");
            return iMAPServer.sendReply(Sock, MakeiMAPMSG.makeReply_del_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable,strTotal));
            //return sendNwaitMSG(strTargetIP, nTargetPort, MakeiMAPMSG.makeReply_del_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable,strTotal));
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_alarm_operation_request(strTargetIP, strMode, strCause, strDong, strHo)");
            e.printStackTrace();
            return false;
        }
    }

    //upgrade 실패시
    public boolean upgrade_pic_reply(Socket Sock, String strTargetIP, String strReason, String ret) {
        try {
            //LOG_INFO("[send_alarm_operation_request] strTargetIP [" + strTargetIP + "], strReason [" + strReason + "], strSpace [" + strSpace + "], strDong [" + strDong + "], strHo [" + strHo + "]");
            //LOG_INFO("[send_alarm_operation_request] strAlias [" + strAlias + "], strAvailable [" + strAvailable + "], strDuplicate [" + strDuplicate + "], strTotal [" + strTotal + "]");
            //return sendNwaitMSG(strTargetIP, nTargetPort, MakeiMAPMSG.failReply_add_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable, strDuplicate, strTotal));
            return iMAPServer.sendReply(Sock, MakeiMAPMSG.Reply_upgrade_pic(ret, strReason));
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_alarm_operation_request(strTargetIP, strMode, strCause, strDong, strHo)");
            e.printStackTrace();
            return false;
        }
    }

    //add 실패시
    public boolean fail_add_pic_reply(Socket Sock, String strTargetIP, String strReason, String strSpace, String strDong, String strHo, String strAlias, String strAvailable, String strDuplicate, String strTotal) {
        try {
            //LOG_INFO("[send_alarm_operation_request] strTargetIP [" + strTargetIP + "], strReason [" + strReason + "], strSpace [" + strSpace + "], strDong [" + strDong + "], strHo [" + strHo + "]");
            //LOG_INFO("[send_alarm_operation_request] strAlias [" + strAlias + "], strAvailable [" + strAvailable + "], strDuplicate [" + strDuplicate + "], strTotal [" + strTotal + "]");
            //return sendNwaitMSG(strTargetIP, nTargetPort, MakeiMAPMSG.failReply_add_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable, strDuplicate, strTotal));
            return iMAPServer.sendReply(Sock, MakeiMAPMSG.failReply_add_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable, strDuplicate, strTotal));
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_alarm_operation_request(strTargetIP, strMode, strCause, strDong, strHo)");
            e.printStackTrace();
            return false;
        }
    }

    //del 실패시
    public boolean fail_del_pic_reply(Socket Sock, String strTargetIP, String strReason, String strSpace, String strDong, String strHo,String strAlias,String strAvailable,String strTotal) {
        try {
            LOG_INFO("[send_alarm_operation_request] strTargetIP [" + strTargetIP + "], strReason [" + strReason + "], strSpace [" + strSpace + "], strDong [" + strDong + "], strHo [" + strHo + "]");
            LOG_INFO("[send_alarm_operation_request] strAlias [" + strAlias + "], strAvailable [" + strAvailable + "],strTotal [" + strTotal + "]");
            return iMAPServer.sendReply(Sock, MakeiMAPMSG.failReply_del_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable, strTotal));
            //return sendNwaitMSG(strTargetIP, nTargetPort, MakeiMAPMSG.failReply_del_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable, strTotal));
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_alarm_operation_request(strTargetIP, strMode, strCause, strDong, strHo)");
            e.printStackTrace();
            return false;
        }
    }

    //down 실패시
    public boolean fail_down_pic_reply(Socket Sock) {
        try {
            //LOG_INFO("[send_alarm_operation_request] strTargetIP [" + strTargetIP + "], strReason [" + strReason + "], strSpace [" + strSpace + "], strDong [" + strDong + "], strHo [" + strHo + "]");
            //LOG_INFO("[send_alarm_operation_request] strAlias [" + strAlias + "], strAvailable [" + strAvailable + "], strDuplicate [" + strDuplicate + "], strTotal [" + strTotal + "]");
            //return sendNwaitMSG(strTargetIP, nTargetPort, MakeiMAPMSG.failReply_add_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable, strDuplicate, strTotal));
            return iMAPServer.sendReply(Sock, MakeiMAPMSG.failReply_down_pic());
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_alarm_operation_request(strTargetIP, strMode, strCause, strDong, strHo)");
            e.printStackTrace();
            return false;
        }
    }

    //down 성공시
    public boolean send_down_pic_reply(Socket Sock) {
        try {
            //LOG_INFO("[send_alarm_operation_request] strTargetIP [" + strTargetIP + "], strReason [" + strReason + "], strSpace [" + strSpace + "], strDong [" + strDong + "], strHo [" + strHo + "]");
            //LOG_INFO("[send_alarm_operation_request] strAlias [" + strAlias + "], strAvailable [" + strAvailable + "], strTotal [" + strTotal + "]");
            return iMAPServer.sendReply(Sock, MakeiMAPMSG.makeReply_down_pic());
            //return sendNwaitMSG(strTargetIP, nTargetPort, MakeiMAPMSG.makeReply_del_pic(strReason, strSpace, strDong, strHo, strAlias, strAvailable,strTotal));
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_alarm_operation_request(strTargetIP, strMode, strCause, strDong, strHo)");
            e.printStackTrace();
            return false;
        }
    }

    public boolean save_facepic_request(String strTargetIP, String strDong, String strHo,String strAlias,String strMethod,String strResult,String strMessage) {
        try {
            LOG_INFO("[send_alarm_operation_request] strTargetIP [" + strTargetIP + "],strDong [" + strDong + "], strHo [" + strHo + "],  strAlias ["+ strAlias +"]");
            LOG_INFO("[send_alarm_operation_request] strMethod [ \"face\" ], strResult [\"pass\"], strMessage [\"null\"]");
            return sendNwaitMSG(strTargetIP, nTargetPort, MakeiMAPMSG.save_facepic_access(strDong, strHo, strAlias, strMethod, strResult, strMessage));
        } catch (Exception e) {
            Log.e(TAG, "[Exception] send_alarm_operation_request(strTargetIP, strMode, strCause, strDong, strHo)");
            e.printStackTrace();
            return false;
        }
    }


}
