package epson.print;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Parcel;
import android.os.Parcelable;

import epson.common.Constants;
import epson.provider.SharedPreferencesProvider;

public class MyPrinter implements Parcelable {
    public static final Creator<MyPrinter> CREATOR = new Creator<MyPrinter>() {
        public MyPrinter createFromParcel(Parcel parcel) {
            return new MyPrinter(parcel);
        }

        public MyPrinter[] newArray(int i) {
            return new MyPrinter[i];
        }
    };
    public static final int PRINTER_IP = 3;
    public static final int PRINTER_LOCAL = 1;
    public static final int PRINTER_REMOTE = 2;
    public static final int PRINTER_UNKNOWN = 0;
    public static final String PRINTER_USB = "USB";
    private String mCommonDeviceName;
    private String mEmailAddress;
    private String mIp;
    private int mLang;
    private int mLocation;
    private String mName;
    private String mPrinterId;
    private int mPrinterIndex;
    private String mScannerId;
    private String mSerialNo;

    public int describeContents() {
        return 0;
    }

    private MyPrinter() {
        mName = null;
        mIp = null;
        mPrinterId = null;
        mScannerId = null;
        mSerialNo = null;
        mEmailAddress = null;
        mLocation = 0;
        mLang = 1;
        mCommonDeviceName = null;
        mPrinterIndex = -1;
    }

    public MyPrinter(String str, String str2, String str3, String str4) {
        mName = null;
        mIp = null;
        mPrinterId = null;
        mScannerId = null;
        mSerialNo = null;
        mEmailAddress = null;
        mLocation = 0;
        mLang = 1;
        mCommonDeviceName = null;
        mPrinterIndex = -1;
        mName = str;
        mIp = str2;
        mPrinterId = str3;
        mSerialNo = str4;
        mLocation = 1;
    }

    public MyPrinter(String str, String str2, String str3, String str4, String str5) {
        mName = null;
        mIp = null;
        mPrinterId = null;
        mScannerId = null;
        mSerialNo = null;
        mEmailAddress = null;
        mLocation = 0;
        mLang = 1;
        mCommonDeviceName = null;
        mPrinterIndex = -1;
        mName = str;
        mIp = str2;
        mPrinterId = str3;
        mSerialNo = str4;
        mEmailAddress = str5;
        mLocation = 2;
    }

    public MyPrinter(String str, String str2, String str3, String str4, String str5, int i) {
        mName = null;
        mIp = null;
        mPrinterId = null;
        mScannerId = null;
        mSerialNo = null;
        mEmailAddress = null;
        mLocation = 0;
        mLang = 1;
        mCommonDeviceName = null;
        mPrinterIndex = -1;
        mName = str;
        mIp = str2;
        mPrinterId = str3;
        mSerialNo = str4;
        mEmailAddress = str5;
        mLocation = i;
    }

    public String getName() {
        return mName;
    }

    public String getIp() {
        return mIp;
    }

    public void setIp(String str) {
        mIp = str;
    }

    public String getPrinterId() {
        return mPrinterId;
    }

    public String getSerialNo() {
        return mSerialNo;
    }

    public String getEmailAddress() {
        return mEmailAddress;
    }

    public int getLocation() {
        return mLocation;
    }

    public void setLocation(int i) {
        mLocation = i;
    }

    public String getCommonDeviceName() {
        return mCommonDeviceName;
    }

    public void setCommonDeviceName(String str) {
        mCommonDeviceName = str;
    }

    public int getPrinterIndex() {
        return mPrinterIndex;
    }

    public void setPrinterIndex(int i) {
        mPrinterIndex = i;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:4:0x000a, code lost:
        r2 = new epson.print.EPPrinterManager(r2).loadRemotePrinterInfo(getEmailAddress());
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public String getRemotePrinterAccessKey(Context r2) {
        /*
            r1 = this;
            java.lang.String r0 = r1.mEmailAddress
            if (r0 == 0) goto L_0x001c
            int r0 = r0.length()
            if (r0 <= 0) goto L_0x001c
            epson.print.EPPrinterManager r0 = new epson.print.EPPrinterManager
            r0.<init>(r2)
            java.lang.String r2 = r1.getEmailAddress()
            epson.print.EPPrinterInfo r2 = r0.loadRemotePrinterInfo(r2)
            if (r2 == 0) goto L_0x001c
            java.lang.String r2 = r2.printerAccessKey
            return r2
        L_0x001c:
            java.lang.String r2 = ""
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.print.MyPrinter.getRemotePrinterAccessKey(android.content.Context):java.lang.String");
    }

    public String getUserDefName(Context context) {
        EPPrinterInfo loadRemotePrinterInfo;
        EPPrinterInfo loadIpPrinterInfo;
        EPPrinterManager ePPrinterManager = new EPPrinterManager(context);
        switch (mLocation) {
            case 2:
                if (!(getEmailAddress() == null || getEmailAddress().length() <= 0 || (loadRemotePrinterInfo = ePPrinterManager.loadRemotePrinterInfo(getEmailAddress())) == null || loadRemotePrinterInfo.userDefName == null || loadRemotePrinterInfo.userDefName.length() <= 0)) {
                    return loadRemotePrinterInfo.userDefName;
                }
            case 3:
                if (!(getPrinterId() == null || getPrinterId().length() <= 0 || (loadIpPrinterInfo = ePPrinterManager.loadIpPrinterInfo(getPrinterId())) == null || loadIpPrinterInfo.userDefName == null || loadIpPrinterInfo.userDefName.length() <= 0)) {
                    return loadIpPrinterInfo.userDefName;
                }
        }
        return mName;
    }

    public String getScannerId() {
        return mScannerId;
    }

    public void setScannerId(String str) {
        mScannerId = str;
    }

    public int getLang() {
        return mLang;
    }

    public void setLang(int i) {
        mLang = i;
    }

    private MyPrinter(Parcel parcel) {
        mName = null;
        mIp = null;
        mPrinterId = null;
        mScannerId = null;
        mSerialNo = null;
        mEmailAddress = null;
        mLocation = 0;
        mLang = 1;
        mCommonDeviceName = null;
        mPrinterIndex = -1;
        mName = parcel.readString();
        mIp = parcel.readString();
        mPrinterId = parcel.readString();
        mSerialNo = parcel.readString();
        mEmailAddress = parcel.readString();
        mLocation = parcel.readInt();
        mScannerId = parcel.readString();
        mLang = parcel.readInt();
        mPrinterIndex = parcel.readInt();
    }

    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(mName);
        parcel.writeString(mIp);
        parcel.writeString(mPrinterId);
        parcel.writeString(mSerialNo);
        parcel.writeString(mEmailAddress);
        parcel.writeInt(mLocation);
        parcel.writeString(mScannerId);
        parcel.writeInt(mLang);
        parcel.writeInt(mPrinterIndex);
    }

    public static MyPrinter getCurPrinter(Context context) {
        MyPrinter myPrinter = new MyPrinter();
        SharedPreferencesProvider.SharedPreferencesMulti instace = SharedPreferencesProvider.getInstace(context);
        myPrinter.mName = instace.getString(Constants.PRINTER_NAME, (String) null);
        myPrinter.mPrinterId = instace.getString(Constants.PRINTER_ID, (String) null);
        myPrinter.mIp = instace.getString(Constants.PRINTER_IP, (String) null);
        myPrinter.mSerialNo = instace.getString(Constants.PRINTER_SERIAL_NO, (String) null);
        myPrinter.mEmailAddress = instace.getString(Constants.PRINTER_EMAIL_ADDRESS, (String) null);
        myPrinter.mLocation = instace.getInt(Constants.PRINTER_LOCATION, 0);
        myPrinter.mLang = instace.getInt(Constants.LANG, 1);
        return myPrinter;
    }

    public void setCurPrinter(Context context) {
        SharedPreferences.Editor edit = context.getSharedPreferences("PrintSetting", 0).edit();
        edit.putString(Constants.PRINTER_NAME, getName());
        edit.putString(Constants.PRINTER_IP, getIp());
        edit.putString(Constants.PRINTER_ID, getPrinterId());
        edit.putString(Constants.PRINTER_SERIAL_NO, getSerialNo());
        edit.putString(Constants.PRINTER_EMAIL_ADDRESS, getEmailAddress());
        edit.putInt(Constants.PRINTER_LOCATION, getLocation());
        edit.putInt(Constants.LANG, getLang());
        edit.remove("PRINTER_ACCESS_KEY");
        edit.commit();
    }

    public static void clearCurPrinter(Context context) {
        SharedPreferences.Editor edit = context.getSharedPreferences("PrintSetting", 0).edit();
        edit.remove(Constants.PRINTER_NAME);
        edit.remove(Constants.PRINTER_IP);
        edit.remove(Constants.PRINTER_ID);
        edit.remove(Constants.PRINTER_SERIAL_NO);
        edit.remove(Constants.PRINTER_EMAIL_ADDRESS);
        edit.remove(Constants.PRINTER_LOCATION);
        edit.remove(Constants.LANG);
        edit.remove("PRINTER_ACCESS_KEY");
        edit.commit();
    }

    public static int getCurrectLocation(Context context) {
        return getCurPrinter(context).getLocation();
    }

    public static boolean isRemotePrinter(Context context) {
        return getCurrectLocation(context) == 2;
    }

    public static String getPrinterDeviceId(Context context, boolean z) {
        MyPrinter curPrinter = getCurPrinter(context);
        String name = curPrinter.getName();
        return (curPrinter.getLocation() != 2 || !z) ? name : getRemotePrinterDeviceIdFromServer(context, curPrinter.getEmailAddress());
    }

    /* JADX WARNING: Code restructure failed: missing block: B:3:0x0009, code lost:
        r7 = epson.print.ecclient.EpsonConnectAccess.getPrinterInfo(r7, r8, new epson.print.MyPrinter((java.lang.String) null, (java.lang.String) null, (java.lang.String) null, (java.lang.String) null, r8).getRemotePrinterAccessKey(r7));
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    static String getRemotePrinterDeviceIdFromServer(Context r7, String r8) {
        /*
            if (r8 == 0) goto L_0x0029
            int r0 = r8.length()
            if (r0 > 0) goto L_0x0009
            goto L_0x0029
        L_0x0009:
            epson.print.MyPrinter r0 = new epson.print.MyPrinter
            r2 = 0
            r3 = 0
            r4 = 0
            r5 = 0
            r1 = r0
            r6 = r8
            r1.<init>(r2, r3, r4, r5, r6)
            java.lang.String r0 = r0.getRemotePrinterAccessKey(r7)
            epson.print.ecclient.EpsonConnectAccess$RemotePrinterInfo r7 = epson.print.ecclient.EpsonConnectAccess.getPrinterInfo(r7, r8, r0)
            if (r7 == 0) goto L_0x0026
            java.lang.String r8 = r7.mDeviceId
            if (r8 != 0) goto L_0x0023
            goto L_0x0026
        L_0x0023:
            java.lang.String r7 = r7.mDeviceId
            return r7
        L_0x0026:
            java.lang.String r7 = ""
            return r7
        L_0x0029:
            java.lang.String r7 = ""
            return r7
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.print.MyPrinter.getRemotePrinterDeviceIdFromServer(android.content.Context, java.lang.String):java.lang.String");
    }

    public static boolean isPrinterRouteOtg(@NonNull Context context) {
        return PRINTER_USB.equals(getCurPrinter(context).getIp());
    }
}
