package E1;

import android.net.Uri;
import android.os.Bundle;
import com.google.android.gms.internal.measurement.C1;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes.dex */
public final class y {

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public static final Pattern f2140m = Pattern.compile("^[a-zA-Z]+[+\\w\\-.]*:");

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final String f2141a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f2142b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f2143c;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final String f2146f;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final boolean f2148h;
    public final boolean i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final String f2149j;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final boolean f2151l;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final ArrayList f2144d = new ArrayList();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final LinkedHashMap f2145e = new LinkedHashMap();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final A6.k f2147g = new A6.k(new x(this, 1));

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final A6.k f2150k = new A6.k(new x(this, 0));

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r13v0, types: [java.util.regex.Matcher] */
    /* JADX WARN: Type inference failed for: r17v0, types: [E1.y] */
    /* JADX WARN: Type inference failed for: r20v6 */
    /* JADX WARN: Type inference failed for: r20v7 */
    /* JADX WARN: Type inference failed for: r3v16, types: [int] */
    /* JADX WARN: Type inference failed for: r3v22 */
    /* JADX WARN: Type inference failed for: r3v24 */
    public y(String str, String str2, String str3) {
        boolean z8;
        List listC;
        List listV0;
        boolean z9;
        this.f2141a = str;
        this.f2142b = str2;
        this.f2143c = str3;
        int i = 0;
        boolean z10 = true;
        if (str != null) {
            Uri uri = Uri.parse(str);
            boolean z11 = uri.getQuery() != null;
            this.f2148h = z11;
            StringBuilder sb = new StringBuilder("^");
            if (!f2140m.matcher(str).find()) {
                sb.append("http[s]?://");
            }
            Pattern patternCompile = Pattern.compile("\\{(.+?)\\}");
            if (z11) {
                Matcher matcher = Pattern.compile("(\\?)").matcher(str);
                if (matcher.find()) {
                    String strSubstring = str.substring(0, matcher.start());
                    P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
                    P6.g.d(patternCompile, "fillInPattern");
                    this.f2151l = a(strSubstring, sb, patternCompile);
                }
                for (String str4 : uri.getQueryParameterNames()) {
                    StringBuilder sb2 = new StringBuilder();
                    String queryParameter = uri.getQueryParameter(str4);
                    if (queryParameter == null) {
                        this.i = z10;
                        queryParameter = str4;
                    }
                    ?? Matcher = patternCompile.matcher(queryParameter);
                    w wVar = new w();
                    int iEnd = i;
                    ?? r32 = z10;
                    while (Matcher.find()) {
                        String strGroup = Matcher.group(r32);
                        if (strGroup == null) {
                            throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
                        }
                        wVar.f2137b.add(strGroup);
                        P6.g.d(queryParameter, "queryParam");
                        String strSubstring2 = queryParameter.substring(iEnd, Matcher.start());
                        P6.g.d(strSubstring2, "this as java.lang.String…ing(startIndex, endIndex)");
                        sb2.append(Pattern.quote(strSubstring2));
                        sb2.append("(.+?)?");
                        iEnd = Matcher.end();
                        r32 = r32 == true ? 1 : 0;
                    }
                    ?? r20 = r32;
                    if (iEnd < queryParameter.length()) {
                        String strSubstring3 = queryParameter.substring(iEnd);
                        P6.g.d(strSubstring3, "this as java.lang.String).substring(startIndex)");
                        sb2.append(Pattern.quote(strSubstring3));
                    }
                    String string = sb2.toString();
                    P6.g.d(string, "argRegex.toString()");
                    wVar.f2136a = X6.n.K(string, ".*", "\\E.*\\Q");
                    LinkedHashMap linkedHashMap = this.f2145e;
                    P6.g.d(str4, "paramName");
                    linkedHashMap.put(str4, wVar);
                    z10 = r20 == true ? 1 : 0;
                    i = 0;
                }
                z9 = z10 ? 1 : 0;
            } else {
                z9 = true;
                P6.g.d(patternCompile, "fillInPattern");
                this.f2151l = a(str, sb, patternCompile);
            }
            String string2 = sb.toString();
            P6.g.d(string2, "uriRegex.toString()");
            this.f2146f = X6.n.K(string2, ".*", "\\E.*\\Q");
            z8 = z9;
        } else {
            z8 = true;
        }
        if (this.f2143c != null) {
            if (!Pattern.compile("^[\\s\\S]+/[\\s\\S]+$").matcher(this.f2143c).matches()) {
                throw new IllegalArgumentException(I1.a.r(new StringBuilder("The given mimeType "), this.f2143c, " does not match to required \"type/subtype\" format").toString());
            }
            String str5 = this.f2143c;
            P6.g.e(str5, "mimeType");
            Pattern patternCompile2 = Pattern.compile("/");
            P6.g.d(patternCompile2, "compile(...)");
            Matcher matcher2 = patternCompile2.matcher(str5);
            if (matcher2.find()) {
                ArrayList arrayList = new ArrayList(10);
                int iEnd2 = 0;
                do {
                    arrayList.add(str5.subSequence(iEnd2, matcher2.start()).toString());
                    iEnd2 = matcher2.end();
                } while (matcher2.find());
                arrayList.add(str5.subSequence(iEnd2, str5.length()).toString());
                listC = arrayList;
            } else {
                listC = C1.C(str5.toString());
            }
            if (listC.isEmpty()) {
                listV0 = B6.t.f1032q;
            } else {
                ListIterator listIterator = listC.listIterator(listC.size());
                while (listIterator.hasPrevious()) {
                    if (((String) listIterator.previous()).length() != 0) {
                        listV0 = B6.k.v0(listIterator.nextIndex() + 1, listC);
                        break;
                    }
                }
                listV0 = B6.t.f1032q;
            }
            this.f2149j = X6.n.K("^(" + ((String) listV0.get(0)) + "|[*]+)/(" + ((String) listV0.get(z8 ? 1 : 0)) + "|[*]+)$", "*|[*]", "[\\s\\S]");
        }
    }

    public static void b(Bundle bundle, String str, String str2, C0102i c0102i) {
        if (c0102i == null) {
            bundle.putString(str, str2);
            return;
        }
        P p3 = c0102i.f2080a;
        P6.g.e(str, "key");
        p3.d(bundle, str, p3.c(str2));
    }

    public final boolean a(String str, StringBuilder sb, Pattern pattern) {
        Matcher matcher = pattern.matcher(str);
        boolean z8 = !X6.e.O(str, ".*");
        int iEnd = 0;
        while (matcher.find()) {
            String strGroup = matcher.group(1);
            if (strGroup == null) {
                throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
            }
            this.f2144d.add(strGroup);
            String strSubstring = str.substring(iEnd, matcher.start());
            P6.g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
            sb.append(Pattern.quote(strSubstring));
            sb.append("([^/]+?)");
            iEnd = matcher.end();
            z8 = false;
        }
        if (iEnd < str.length()) {
            String strSubstring2 = str.substring(iEnd);
            P6.g.d(strSubstring2, "this as java.lang.String).substring(startIndex)");
            sb.append(Pattern.quote(strSubstring2));
        }
        sb.append("($|(\\?(.)*)|(\\#(.)*))");
        return z8;
    }

    public final boolean equals(Object obj) {
        if (obj != null && (obj instanceof y)) {
            y yVar = (y) obj;
            if (P6.g.a(this.f2141a, yVar.f2141a) && P6.g.a(this.f2142b, yVar.f2142b) && P6.g.a(this.f2143c, yVar.f2143c)) {
                return true;
            }
        }
        return false;
    }

    public final int hashCode() {
        String str = this.f2141a;
        int iHashCode = (str != null ? str.hashCode() : 0) * 31;
        String str2 = this.f2142b;
        int iHashCode2 = (iHashCode + (str2 != null ? str2.hashCode() : 0)) * 31;
        String str3 = this.f2143c;
        return iHashCode2 + (str3 != null ? str3.hashCode() : 0);
    }
}
