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

package com.ntels.onecable.common.db;

import com.ntels.onecable.common.db.entity.TblCode;
import com.ntels.onecable.common.db.entity.TblCodeList;
import com.ntels.onecable.common.db.entity.TblLoginInfo;
import com.ntels.onecable.common.db.entity.TblTimeZone;
import com.ntels.onecable.common.util.Dlog;
import com.ntels.onecable.common.util.Util;

/**
 * <pre>
 * 1. ClassName :   SqlManager
 * 2. FileName  :   SqlManager.java
 * 3. Package   :   com.ntels.onecable.common.db
 * 4. Date      :   2016-12-05
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class SqlManager {

    private Util util = new Util();

    public String qryLoginInfo() {
        String sSql = "";
        sSql += "\n   SELECT * ";
        sSql += "\n     FROM " + TblLoginInfo.TABLE_NAME;
        sSql += ";";
        Dlog.v("=========== qryLoginInfo ===========");
        Dlog.v(sSql);
        Dlog.v("=========== qryLoginInfo ===========");
        return sSql;
    }

    /**
     * 로그인 정보 자동로그인 업데이트 쿼리 생성.
     *
     * @param bAutoLogin 자동로그인 여부.
     * @return Query string
     */
    public String qryUpdateLoginInfoAutoLogin(Boolean bAutoLogin) {
        String sSql = "";
        String sAutoLogin = "N";
        if (bAutoLogin) {
            sAutoLogin = "Y";
        }
        sSql = "";
        sSql += "\n UPDATE " + TblLoginInfo.TABLE_NAME;
        sSql += "\n    SET " + TblLoginInfo.AUTO_LOGIN_YN + " = '" + sAutoLogin + "'";
        sSql += ";";
        Dlog.v("=========== qryUpdateLoginInfoAutoLogin ===========");
        Dlog.v(sSql);
        Dlog.v("=========== qryUpdateLoginInfoAutoLogin ===========");
        return sSql;
    }

    //로그인 정보 아이디 업데이트
    public String qryUpdateLoginInfoLoginPass(String sPass) {
        String sSql = "";
        sSql = "";
        sSql += "\n UPDATE " + TblLoginInfo.TABLE_NAME;
        sSql += "\n    SET " + TblLoginInfo.LOGIN_PASS + " = '" + util.getInsetValues(sPass) + "'";
        sSql += ";";
        Dlog.v("=========== qryUpdateLoginInfoLoginPass ===========");
        Dlog.v(sSql);
        Dlog.v("=========== qryUpdateLoginInfoLoginPass ===========");
        return sSql;
    }

    /**
     * 로그인 정보 추가 쿼리 생성.
     *
     * @param sLogin_Id 로그인 아이디
     * @param sPass 로그인 패스워드
     * @param bSaveId 아이디 저장 여부
     * @param bAutoLogin 자동 로그인 여부
     * @param bView
     * @param bPush 푸쉬 수신 여부
     * @return
     */
    public String qryInsertLoginInfo(String sLogin_Id, String sPass, Boolean bSaveId, Boolean bAutoLogin, Boolean bView, Boolean bPush) {
        String sSql = "";
        String sSaveId = "N";
        if (bSaveId) {
            sSaveId = "Y";
        }
        String sAutoLogin = "N";
        if (bAutoLogin) {
            sAutoLogin = "Y";
        }
        String sView = "N";
        if (bView) {
            sView = "Y";
        }
        String sPush = "N";
        if (bPush) {
            sPush = "Y";
        }
        sSql = "";
        sSql += "\n Insert Into " + TblLoginInfo.TABLE_NAME;
        sSql += "\n ( " + TblLoginInfo.LOGIN_ID;
        sSql += "\n , " + TblLoginInfo.LOGIN_PASS;
        sSql += "\n , " + TblLoginInfo.SAVE_ID_YN;
        sSql += "\n , " + TblLoginInfo.AUTO_LOGIN_YN;
        sSql += "\n , " + TblLoginInfo.MANUAL_NOT_VIEW_YN;
        sSql += "\n , " + TblLoginInfo.PUSH_YN;
        sSql += "\n ) values  ";
        sSql += "\n ( '" + util.getInsetValues(sLogin_Id) + "'";
        sSql += "\n , '" + util.getInsetValues(sPass) + "'";
        sSql += "\n , '" + util.getInsetValues(sSaveId) + "'";
        sSql += "\n , '" + util.getInsetValues(sAutoLogin) + "'";
        sSql += "\n , '" + util.getInsetValues(sView) + "'";
        sSql += "\n , '" + util.getInsetValues(sPush) + "'";
        sSql += "\n ) ";
        sSql += ";";
        Dlog.v("=========== qryInsertLoginInfo ===========");
        Dlog.v(sSql);
        Dlog.v("=========== qryInsertLoginInfo ===========");
        return sSql;
    }

    /**
     * 로그인 정보 삭제 쿼리 생성.
     *
     * @return Query string
     */
    public String qryDelLoginInfo() {
        String sSql = "";
        sSql = "";
        sSql += "\n Delete From " + TblLoginInfo.TABLE_NAME;
        sSql += ";";
        Dlog.v("=========== qryInsertLoginInfo ===========");
        Dlog.v(sSql);
        Dlog.v("=========== qryInsertLoginInfo ===========");
        return sSql;
    }

}
