package epson.print.inkrpln;

import android.content.Context;

import com.epson.mobilephone.common.escpr.EPS_REDYINKINFO;
import com.epson.mobilephone.common.escpr.EscprLib;
import com.epson.mobilephone.common.maintain2.MaintainPrinter2;

import epson.print.MyPrinter;

public class PrinterAdapter {
    private static final int EMA_RETRY_COUNT = 0;
    private static final int ESCPR_LIB_EMA_ACTIVATED = 1;
    private static final int ESCPR_LIB_EMA_SUPPORTED = 65536;

    public String getSerialNo(@NonNull Context context) {
        return MyPrinter.getCurPrinter(context).getSerialNo();
    }

    public String getNonRemotePrinterDeviceId(@NonNull Context context) {
        return MyPrinter.getPrinterDeviceId(context, false);
    }

    public boolean isRemotePrinter(@NonNull Context context) {
        return MyPrinter.isRemotePrinter(context);
    }

    public void activateEma() {
        localActivateEma(MaintainPrinter2.getInstance());
    }

    private static void localActivateEma(@NonNull MaintainPrinter2 maintainPrinter2) {
        int[] iArr = new int[2];
        if (maintainPrinter2.getEmaStatus(iArr) == 0) {
            if ((iArr[0] & 65536) != 0 && (iArr[0] & 1) == 0) {
                for (int i = 0; i <= 0 && maintainPrinter2.setEmaStatus(1) != 0; i++) {
                }
            }
        }
    }

    @Nullable
    public EPS_REDYINKINFO getReadyInkInfo() {
        EscprLib mEscpLib = MaintainPrinter2.getInstance().getMEscpLib();
        EPS_REDYINKINFO eps_redyinkinfo = new EPS_REDYINKINFO();
        if (mEscpLib.epsGetReadyPrintStatus(eps_redyinkinfo) != 0) {
            return null;
        }
        return eps_redyinkinfo;
    }

    public void activateEma(EPS_REDYINKINFO eps_redyinkinfo) {
        if (eps_redyinkinfo != null && (eps_redyinkinfo.emaStatus & 65536) != 0 && (eps_redyinkinfo.emaStatus & 1) == 0) {
            MaintainPrinter2 instance = MaintainPrinter2.getInstance();
            for (int i = 0; i <= 0 && instance.setEmaStatus(1) != 0; i++) {
            }
        }
    }
}
