package com.epson.mobilephone.common.maintain2;

import android.content.Context;

import com.epson.mobilephone.common.escpr.EscprLib;

import java.util.EnumMap;

public class MaintainPrinter2 {
    public static final int STATUS_BUSY = 2;
    public static final int STATUS_CANCELLING = 3;
    public static final int STATUS_ERROR = 4;
    public static final int STATUS_IDEL = 0;
    public static final int STATUS_PRINTING = 1;
    private static Object lockObj = new Object();
    private static final MaintainPrinter2 maintainPrinter_INSTANCE = new MaintainPrinter2();
    protected EscprLib mEscpLib = EscprLib.getInstance();
    protected MaintainPrinterInfo2 mPrinterInfor = new MaintainPrinterInfo2();
    protected int mSearchPos = 0;

    private MaintainPrinter2() {
    }

    public static MaintainPrinter2 getInstance() {
        return maintainPrinter_INSTANCE;
    }

    public void setMSearchPos(int i) {
        mSearchPos = i;
    }

    public EscprLib getMEscpLib() {
        return mEscpLib;
    }

    public MaintainPrinterInfo2 getMPrinterInfor() {
        return mPrinterInfor;
    }

    public int getMSearchPos() {
        return mSearchPos;
    }

    public int doInitDriver(Context context, int i) {
        EpLog.i("MaintainPrinter2", " @@@@@@@    doInitDriver                 @");
        EpLog.m77i(mEscpLib.is64bit() ? "Native is operating at ☆ 64 bit !!" : "Native is operating at 32 bit");
        return mEscpLib.epsWrapperInitDriver(context, i);
    }

    public int doReleaseDriver() {
        EpLog.i("MaintainPrinter2", " xxxxxxx    doReleaseDriver                x");
        return mEscpLib.release_driver();
    }

    public int doFindPrinter(int i, int i2) {
        int doFindPrinter;
        synchronized (lockObj) {
            EpLog.i("MaintainPrinter2", "**********Call do find printer************");
            mEscpLib.setSearchStt(true);
            mEscpLib.resetIPAdressCheck();
            EpLog.i("MaintainPrinter2", "findType = " + i);
            doFindPrinter = mEscpLib.doFindPrinter(i, i2);
            EpLog.i("MaintainPrinter2", "**********Finish do find printer************");
        }
        return doFindPrinter;
    }

    public int doGetLang() {
        return mEscpLib.get_lang();
    }

    public String doGetIp() {
        return mEscpLib.epsWrapperGetIp();
    }

    public String doGetId() {
        return mEscpLib.epsWrapperGetId();
    }

    public int doCancelFindPrinter() {
        mEscpLib.setSearchStt(false);
        return mEscpLib.epsWrapperCancelFindPrinter();
    }

    public int doSetPrinter() {
        return mEscpLib.set_printer(mSearchPos);
    }

    public int doGetStatus() {
        int epsWrapperGetStatus;
        synchronized (lockObj) {
            epsWrapperGetStatus = mEscpLib.epsWrapperGetStatus(mPrinterInfor.getMStatus());
        }
        return epsWrapperGetStatus;
    }

    public int doDoMainteCmd(int i) {
        int epsWrapperDoMainteCmd;
        synchronized (lockObj) {
            EpLog.i("MaintainPrinter2", "**********doDoMainteCmd************");
            epsWrapperDoMainteCmd = mEscpLib.epsWrapperDoMainteCmd(i);
        }
        return epsWrapperDoMainteCmd;
    }

    public int doGetInkInfo() {
        int epsWrapperGetInkInfo2;
        synchronized (lockObj) {
            epsWrapperGetInkInfo2 = mEscpLib.epsWrapperGetInkInfo2(mPrinterInfor);
        }
        return epsWrapperGetInkInfo2;
    }

    public int doProbePrinter(int i, String str, String str2, int i2) {
        int epsWrapperProbePrinter2;
        synchronized (lockObj) {
            EpLog.i("MaintainPrinter2", "**********Call doProbePrinter************");
            mEscpLib.resetIPAdressCheck();
            epsWrapperProbePrinter2 = mEscpLib.epsWrapperProbePrinter2(i, str, str2, i2);
            if (epsWrapperProbePrinter2 < 0) {
                EpLog.m72e("MaintainPrinter2", "ret=" + epsWrapperProbePrinter2);
            }
            EpLog.i("MaintainPrinter2", "**********Finish doProbePrinter************");
        }
        return epsWrapperProbePrinter2;
    }

    private int[] getStatus() {
        return getMPrinterInfor().getMStatus();
    }

    public int[] getMediaInfo(int i, int i2) {
        return mEscpLib.epsWrapperGetMediaInfo(i, i2);
    }

    public int[] getPaperInfo() {
        int[] epsWrapperGetPaperInfo;
        synchronized (lockObj) {
            epsWrapperGetPaperInfo = mEscpLib.epsWrapperGetPaperInfo();
        }
        return epsWrapperGetPaperInfo;
    }

    public int getFirmwareInfo(EnumMap<EscprLib.PrinterFirmInfo, String> enumMap) {
        int firmwareInfo;
        synchronized (lockObj) {
            firmwareInfo = mEscpLib.getFirmwareInfo(enumMap);
        }
        return firmwareInfo;
    }

    public int getBatteryInfo(BatteryInfo batteryInfo) {
        int batteryInfo2;
        synchronized (lockObj) {
            batteryInfo2 = mEscpLib.getBatteryInfo(batteryInfo);
        }
        return batteryInfo2;
    }

    public int getBatteryInfo(BatteryInfoEx batteryInfoEx) {
        int batteryInfoEx2;
        synchronized (lockObj) {
            batteryInfoEx2 = mEscpLib.getBatteryInfoEx(batteryInfoEx);
        }
        return batteryInfoEx2;
    }

    public int[] getMaintenanceBoxInformation() {
        int[] epsWrapperGetMaintenanceBoxInformation;
        synchronized (lockObj) {
            epsWrapperGetMaintenanceBoxInformation = mEscpLib.epsWrapperGetMaintenanceBoxInformation();
        }
        return epsWrapperGetMaintenanceBoxInformation;
    }

    public int getEmaStatus(int[] iArr) {
        int epsWrapperGetEmaStatus;
        synchronized (lockObj) {
            epsWrapperGetEmaStatus = mEscpLib.epsWrapperGetEmaStatus(iArr);
        }
        return epsWrapperGetEmaStatus;
    }

    public int setEmaStatus(int i) {
        int epsWrapperSetEmaStatus;
        synchronized (lockObj) {
            epsWrapperSetEmaStatus = mEscpLib.epsWrapperSetEmaStatus(i);
        }
        return epsWrapperSetEmaStatus;
    }
}
