package com.neptune.modules;

import com.neptune.base.NeptuneAppMgmt;
import com.neptune.utils.Convert;
import com.neptune.utils.MyLog;
import com.pax.dal.ISys;
import com.pax.dal.entity.BaseInfo;
import com.pax.dal.entity.EBeepMode;
import com.pax.dal.entity.ENavigationKey;
import com.pax.dal.entity.ETermInfoKey;
import com.pax.dal.entity.ETouchMode;

import java.util.Locale;
import java.util.Map;

public class Sys {

    private static Sys system;
    private ISys iSys = null;

    private Sys() {
        iSys = NeptuneAppMgmt.getDal().getSys();
    }

    public static Sys getInstance() {
        if (system == null) {
            system = new Sys();
        }
        return system;
    }

    public void beep(final EBeepMode beepMode, final int delayTime) {
        iSys.beep(beepMode, delayTime);
        MyLog.logI("beep");
    }

    public Map<ETermInfoKey, String> getTermInfo() {
        return iSys.getTermInfo();
    }

    public String getRadom(int len) {
        byte[] random = iSys.getRandom(len);
        if (random != null) {
            MyLog.logI("getRadom");
            return Convert.getInstance().bcdToStr(random);
        } else {
            MyLog.logE( "return null");
            return "null";
        }

    }

    public String getDevInterfaceVer() {
        String verString = iSys.getDevInterfaceVer();
        MyLog.logI("getDevInterfaceVer");
        return "version of device interface:" + verString;
    }

    public void showNavigationBar(boolean flag) {
        iSys.showNavigationBar(flag);
        MyLog.logI("showNavigationBar");
    }

    public void enableNavigationBar(boolean flag) {
        iSys.enableNavigationBar(flag);
        MyLog.logI("enableNavigationBar");
    }

    public void enableNavigationKey(ENavigationKey navigationKey, boolean flag) {
        iSys.enableNavigationKey(navigationKey, flag);
        MyLog.logI("enableNavigationKey");
    }

    public boolean isNavigationBarVisible() {
        boolean res = true;
        res = iSys.isNavigationBarVisible();
        MyLog.logI("isNavigationBarVisible");
        return res;
    }

    public boolean isNavigationBarEnabled() {
        boolean res = true;
        res = iSys.isNavigationBarEnabled();
        MyLog.logI("isNavigationBarEnabled");
        return res;
    }

    public boolean isNavigationKeyEnabled(ENavigationKey navigationKey) {
        boolean res = true;
        res = iSys.isNavigationKeyEnabled(navigationKey);
        MyLog.logI("isNavigationKeyEnabled");
        return res;
    }

    public void showStatusBar(boolean flag) {
        iSys.showStatusBar(flag);
        MyLog.logI("showStatusBar");
    }

    public void enableStatusBar(boolean flag) {
        iSys.enableStatusBar(flag);
        MyLog.logI("enableStatusBar");
    }

    public boolean isStatusBarEnabled() {
        boolean res = true;
        res = iSys.isStatusBarEnabled();
        MyLog.logI("isStatusBarEnabled");
        return res;
    }

    public boolean isStatusBarVisible() {
        boolean res = true;
        res = iSys.isStatusBarVisible();
        MyLog.logI("isStatusBarVisible");
        return res;
    }

    public void resetStatusBar() {
        iSys.resetStatusBar();
        MyLog.logI("resetStatusBar");
    }

    public void enablePowerKey(boolean flag) {
        iSys.enablePowerKey(flag);
        MyLog.logI("enablePowerKey");
    }

    public boolean isPowerKeyEnabled() {
        boolean res = true;
        res = iSys.isPowerKeyEnabled();
        MyLog.logI("isPowerKeyEnabled");
        return res;
    }

    public void setSettingsNeedPassword(boolean flag) {
        iSys.setSettingsNeedPassword(flag);
        MyLog.logI("setSettingsNeedPassword");
    }

    public void reboot() {
        iSys.reboot();
        MyLog.logI("reboot");
    }

    public void shutdown() {
        iSys.shutdown();
        MyLog.logI("shutdown");
    }

    public void switchTouchMode(ETouchMode touchMode) {
        iSys.switchTouchMode(touchMode);
        MyLog.logI("switchTouchMode");
    }

    public int getAppLogs(String storePath, String startDate, String endDate) {
        int res = iSys.getAppLogs(storePath, startDate, endDate);
        MyLog.logI("getAppLogs");
        return res;
    }

    public String readTUSN() {
        String res = iSys.readTUSN();
        MyLog.logI("readTUSN");
        return res;
    }
    
    public boolean isOnBase(){
        boolean isOnBase = iSys.isOnBase();
        MyLog.logI("isOnBase");
        return isOnBase;
    }
    
    public BaseInfo getBaseInfo(){
        BaseInfo baseInfo = iSys.getBaseInfo();
        MyLog.logI("getBaseInfo");
        return baseInfo;
    }
    
    public String getSystemLanguage(){
        String language = iSys.getSystemLanguage();
        MyLog.logI("getSystemLanguage");
        return language;
    }
    
    public void setSystemLanguage(Locale locale){
        iSys.setSystemLanguage(locale);
        MyLog.logI("setSystemLanguage");
    }
    
    public String getPN(){
        String pn = iSys.getPN();
        MyLog.logI("getPN");
        return pn;
    }
}
