package epson.epsonconnectregistration;

import android.media.ExifInterface;
import android.net.Uri;
import com.box.androidsdk.content.BoxConstants;

import epson.print.BuildConfig;

public class SoapWEBSETUPDataInfo extends SoapConfigDataParser {
    static final int AVAILABLEWEBMODE_DISABLE = 1;
    static final int AVAILABLEWEBMODE_ENABLE = 16;
    static final int AVAILABLEWEBMODE_ENABLE_PRINT = 8;
    static final int AVAILABLEWEBMODE_ENABLE_REMOVEACCOUNT = 4;
    static final int AVAILABLEWEBMODE_ENABLE_REMOVEACCOUNT_PRINT = 2;
    static final String GROUP_ID = "WEBSETUPDataInfo";
    static final String ID_ADMIN_PASSWORD = "AdminPassword";
    static final String ID_ADMIN_URL = "AdminURL";
    static final String ID_AVAILABLE_MODE = "AvailableWebMode";
    static final String ID_MODE = "WebMode";
    static final String ID_PRINTER_MAILADDRESS = "PrinterMailAddress";
    static final String ID_SERVER_URL = "WebServerURL";
    static final String ID_SETUP_LANGUAGE = "WebSetupLanguage";
    static final String ID_SETUP_RESULT = "WebSetupResult";
    static final String ID_VERSION = "Version";
    static final String ID_WEBSERVER_STATUS = "WebServerStatus";
    static final String ID_XMPPSERVER_STATUS = "XMPPServerStatus";
    static final String RESULT_NOT_WORKING = "0";
    static final String RESULT_SUCCESS = "2";
    static final String RESULT_WORKING = "1";
    static final String SERVER_STATUS_DISABLE = "0";
    static final String SERVER_STATUS_ENABLE = "2";
    private static final String TAG = "SoapWEBSETUPDataInfo";

    public SoapWEBSETUPDataInfo() {
        super(GROUP_ID);
    }

    public boolean isUnregisteredECPrinter() {
        EpLog.i(TAG, "Enter isUnregisteredECPrinter");
        if (!getRetVal()) {
            EpLog.i(TAG, "return = " + getRetVal());
            return false;
        }
        try {
            Integer valueOf = Integer.valueOf(Integer.parseInt(getValue(ID_AVAILABLE_MODE), 16));
            if (ExifInterface.GPS_MEASUREMENT_2D.equals(getValue(ID_WEBSERVER_STATUS)) && ExifInterface.GPS_MEASUREMENT_2D.equals(getValue(ID_XMPPSERVER_STATUS))) {
                return false;
            }
            if ((valueOf.intValue() & 8) == 0 && (valueOf.intValue() & 16) == 0) {
                EpLog.i(TAG, "Cannot enable EC without delete account -> unregistered");
                return true;
            }
            if (BoxConstants.ROOT_FOLDER_ID.equals(getValue(ID_WEBSERVER_STATUS)) || BoxConstants.ROOT_FOLDER_ID.equals(getValue(ID_XMPPSERVER_STATUS))) {
                Double valueOf2 = Double.valueOf(Double.parseDouble(getValue(ID_VERSION)));
                Integer valueOf3 = Integer.valueOf(valueOf2.intValue());
                Integer valueOf4 = Integer.valueOf(new Double((valueOf2.doubleValue() - (valueOf2.intValue())) * 100.0d).intValue());
                if (valueOf3.intValue() == 1 && valueOf4.intValue() == 0) {
                    EpLog.i(TAG, "WebServerStatus:disable or XMPPServerStatus:disable -> unregistered");
                    return true;
                }
            }
            return false;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public ECStatus checkECPrinterStatus() {
        EpLog.i(TAG, "Enter isUnregisteredECPrinter");
        if (!getRetVal()) {
            EpLog.i(TAG, "return = " + getRetVal());
            return ECStatus.ERROR_CANNOT_ENABLE;
        }
        try {
            Integer valueOf = Integer.valueOf(Integer.parseInt(getValue(ID_AVAILABLE_MODE), 16));
            if (ExifInterface.GPS_MEASUREMENT_2D.equals(getValue(ID_WEBSERVER_STATUS)) && ExifInterface.GPS_MEASUREMENT_2D.equals(getValue(ID_XMPPSERVER_STATUS))) {
                return ECStatus.ERROR_PRINTER_EC_REGISTERED;
            }
            if ((valueOf.intValue() & 8) == 0 && (valueOf.intValue() & 16) == 0) {
                EpLog.i(TAG, "Cannot enable EC without delete account -> unregistered");
                return ECStatus.ERROR_NONE;
            }
            if (BoxConstants.ROOT_FOLDER_ID.equals(getValue(ID_WEBSERVER_STATUS)) || BoxConstants.ROOT_FOLDER_ID.equals(getValue(ID_XMPPSERVER_STATUS))) {
                Double valueOf2 = Double.valueOf(Double.parseDouble(getValue(ID_VERSION)));
                Integer valueOf3 = Integer.valueOf(valueOf2.intValue());
                Integer valueOf4 = Integer.valueOf(new Double((valueOf2.doubleValue() - (valueOf2.intValue())) * 100.0d).intValue());
                if (valueOf3.intValue() != 1 || valueOf4.intValue() != 0) {
                    return ECStatus.ERROR_PRINTER_NOT_SUPPORT_EC;
                }
                EpLog.i(TAG, "WebServerStatus:disable or XMPPServerStatus:disable -> unregistered");
                return ECStatus.ERROR_NONE;
            }
            return ECStatus.ERROR_CANNOT_ENABLE;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public boolean inProgress() {
        EpLog.i(TAG, "Enter inProgress");
        if (!getRetVal()) {
            EpLog.i(TAG, "return = " + getRetVal());
            return false;
        } else if (!RESULT_WORKING.equals(getValue(ID_SETUP_RESULT))) {
            return false;
        } else {
            EpLog.i(TAG, "Working");
            return true;
        }
    }

    public boolean isSucceeded() {
        String value;
        EpLog.i(TAG, "Enter isSucceeded");
        if (!getRetVal()) {
            EpLog.i(TAG, "return = " + getRetVal());
            return false;
        } else if (!ExifInterface.GPS_MEASUREMENT_2D.equals(getValue(ID_SETUP_RESULT)) || (value = getValue(ID_ADMIN_URL)) == null || value.isEmpty()) {
            return false;
        } else {
            EpLog.i(TAG, "Succeeded");
            return true;
        }
    }

    public Uri getRegistrationUri() {
        EpLog.i(TAG, "Enter isSucceeded");
        if (!getRetVal()) {
            EpLog.i(TAG, "return = " + getRetVal());
            return null;
        }
        try {
            Uri parse = Uri.parse(getValue(ID_ADMIN_URL));
            if (parse == null) {
                return null;
            }
            Uri build = new Uri.Builder().scheme(parse.getScheme()).authority(parse.getAuthority()).path(parse.getPath().replace("/setup/", "/nsetup/")).encodedQuery(parse.getQuery()).appendQueryParameter("from", "Alpha".equals(BuildConfig.FLAVOR) ? "setuptool" : "printerfinder").build();
            EpLog.i(TAG, "rebuildUri = " + build);
            return build;
        } catch (NullPointerException e) {
            e.printStackTrace();
            return null;
        }
    }
}
