package epson.epsonconnectregistration;

import android.content.Context;
import android.net.Uri;

import epson.print.BuildConfig;

import java.util.UUID;

public class SoapRequestFactory {
    private static final String PRINER_KEY = "Y2OFL0wVYau52Rlrt7vNpt/8T4F4IjTMvqP1qn4Id0ToRYTlJLxG1CnD9C49Bl205RGyK23HeJzW+TX6HX7m6HwKuiJJKl+K5WQ6fLBY5JU";
    private static final String PRINER_KEY2 = "w4Wv3krd2XpBQbvkSX/ZvnbBvIPBW2Msq0E5VwlZX9SkiGHgynhJzOO+flksH6SEieMYlxNjeIBWdXCTu+QuXwO5zDZ89RjQmn7Qm/qYTNQ=";
    private static final String TAG_DESTINATION = "%DESTINATION%";
    private static final String TAG_GROUPID = "%GROUPID%";
    private static final String TAG_LANG = "%LANG%";
    private static final String TAG_PRINER_KEY = "%PRINER_KEY%";
    private static final String TAG_UUID = "%UUID%";
    private static final String XML_GETREQUEST = "soap/getrequest.xml";
    private static final String XML_GETREQUEST_WEBSETUP = "soap/getrequest_WEBSETUP.xml";
    private static final String XML_SETREQUEST_WEBSETUP = "soap/setrequest_WEBSETUP.xml";

    public static String createGetRequest(Context context, Uri uri) {
        return getXmlTemplate(context, XML_GETREQUEST).replace(TAG_DESTINATION, uri.toString()).replace(TAG_UUID, getUUID());
    }

    public static String createGetRequestWEBSETUP(Context context, Uri uri) {
        return getXmlTemplate(context, XML_GETREQUEST_WEBSETUP).replace(TAG_DESTINATION, uri.toString()).replace(TAG_UUID, getUUID());
    }

    public static String createSetRequestWEBSETUP(Context context, Uri uri, String str) {
        String replace = getXmlTemplate(context, XML_SETREQUEST_WEBSETUP).replace(TAG_DESTINATION, uri.toString()).replace(TAG_UUID, getUUID()).replace(TAG_LANG, str);
        if ("Beta".equals(BuildConfig.FLAVOR)) {
            return replace.replace(TAG_PRINER_KEY, PRINER_KEY2);
        }
        return replace.replace(TAG_PRINER_KEY, PRINER_KEY);
    }

    /* JADX WARNING: Removed duplicated region for block: B:20:0x0037 A[Catch:{ Exception -> 0x003b }] */
    /* JADX WARNING: Removed duplicated region for block: B:24:0x003f A[Catch:{ Exception -> 0x003b }] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static java.lang.String getXmlTemplate(android.content.Context r4, java.lang.String r5) {
        /*
            java.lang.StringBuffer r0 = new java.lang.StringBuffer
            r0.<init>()
            r1 = 0
            android.content.res.AssetManager r4 = r4.getAssets()     // Catch:{ all -> 0x0032 }
            java.io.InputStream r4 = r4.open(r5)     // Catch:{ all -> 0x0032 }
            java.io.BufferedReader r5 = new java.io.BufferedReader     // Catch:{ all -> 0x0030 }
            java.io.InputStreamReader r2 = new java.io.InputStreamReader     // Catch:{ all -> 0x0030 }
            r2.<init>(r4)     // Catch:{ all -> 0x0030 }
            r5.<init>(r2)     // Catch:{ all -> 0x0030 }
        L_0x0018:
            java.lang.String r1 = r5.readLine()     // Catch:{ all -> 0x002b }
            if (r1 == 0) goto L_0x0022
            r0.append(r1)     // Catch:{ all -> 0x002b }
            goto L_0x0018
        L_0x0022:
            if (r4 == 0) goto L_0x0027
            r4.close()     // Catch:{ Exception -> 0x003b }
        L_0x0027:
            r5.close()     // Catch:{ Exception -> 0x003b }
            goto L_0x0046
        L_0x002b:
            r1 = move-exception
            r3 = r1
            r1 = r5
            r5 = r3
            goto L_0x0035
        L_0x0030:
            r5 = move-exception
            goto L_0x0035
        L_0x0032:
            r4 = move-exception
            r5 = r4
            r4 = r1
        L_0x0035:
            if (r4 == 0) goto L_0x003d
            r4.close()     // Catch:{ Exception -> 0x003b }
            goto L_0x003d
        L_0x003b:
            r4 = move-exception
            goto L_0x0043
        L_0x003d:
            if (r1 == 0) goto L_0x0042
            r1.close()     // Catch:{ Exception -> 0x003b }
        L_0x0042:
            throw r5     // Catch:{ Exception -> 0x003b }
        L_0x0043:
            r4.printStackTrace()
        L_0x0046:
            java.lang.String r4 = r0.toString()
            return r4
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.epsonconnectregistration.SoapRequestFactory.getXmlTemplate(android.content.Context, java.lang.String):java.lang.String");
    }

    private static String getUUID() {
        return UUID.randomUUID().toString();
    }
}
