package e7;

import com.fasterxml.jackson.core.JsonPointer;
import e7.b;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jn.i;
import jn.o;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import kotlin.text.x;
import kotlin.text.y;
import sm.c0;
import sm.k0;
import sm.p0;
import sm.q0;
import sm.v;
import sm.x0;
import sm.y0;

/* loaded from: classes.dex */
public final class d implements b {

    /* renamed from: h, reason: collision with root package name */
    public static final a f16822h = new a(null);

    /* renamed from: i, reason: collision with root package name */
    private static final Set f16823i;

    /* renamed from: j, reason: collision with root package name */
    private static final Set f16824j;

    /* renamed from: k, reason: collision with root package name */
    private static final Set f16825k;

    /* renamed from: l, reason: collision with root package name */
    private static final Set f16826l;

    /* renamed from: m, reason: collision with root package name */
    private static final Set f16827m;

    /* renamed from: n, reason: collision with root package name */
    private static final Set f16828n;

    /* renamed from: o, reason: collision with root package name */
    private static final Set f16829o;

    /* renamed from: p, reason: collision with root package name */
    private static final Set f16830p;

    /* renamed from: q, reason: collision with root package name */
    private static final Set f16831q;

    /* renamed from: r, reason: collision with root package name */
    private static final Set f16832r;

    /* renamed from: s, reason: collision with root package name */
    private static final b f16833s;

    /* renamed from: t, reason: collision with root package name */
    private static final b f16834t;

    /* renamed from: u, reason: collision with root package name */
    private static final b f16835u;

    /* renamed from: v, reason: collision with root package name */
    private static final b f16836v;

    /* renamed from: w, reason: collision with root package name */
    private static final b f16837w;

    /* renamed from: x, reason: collision with root package name */
    private static final b f16838x;

    /* renamed from: y, reason: collision with root package name */
    private static final b f16839y;

    /* renamed from: z, reason: collision with root package name */
    private static final b f16840z;

    /* renamed from: b, reason: collision with root package name */
    private final String f16841b;

    /* renamed from: c, reason: collision with root package name */
    private final Set f16842c;

    /* renamed from: d, reason: collision with root package name */
    private final Map f16843d;

    /* renamed from: e, reason: collision with root package name */
    private final Map f16844e;

    /* renamed from: f, reason: collision with root package name */
    private final Map f16845f;

    /* renamed from: g, reason: collision with root package name */
    private final Map f16846g;

    /* loaded from: classes.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(k kVar) {
            this();
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final String i(char c10) {
            StringBuilder sb2 = new StringBuilder();
            int i10 = c10 & 255;
            sb2.append('%');
            sb2.append("0123456789ABCDEF".charAt(i10 >> 4));
            sb2.append("0123456789ABCDEF".charAt(i10 & 15));
            String sb3 = sb2.toString();
            t.f(sb3, "toString(...)");
            return sb3;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final void j(StringBuilder sb2, byte b10) {
            int i10 = b10 & 255;
            sb2.append('%');
            sb2.append("0123456789ABCDEF".charAt(i10 >> 4));
            sb2.append("0123456789ABCDEF".charAt(i10 & 15));
        }

        public final b c() {
            return d.f16837w;
        }

        public final b d() {
            return d.f16833s;
        }

        public final b e() {
            return d.f16835u;
        }

        public final b f() {
            return d.f16836v;
        }

        public final b g() {
            return d.f16840z;
        }

        public final b h() {
            return d.f16834t;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    static {
        List x02;
        Set X0;
        Set X02;
        Set k10;
        Set h10;
        Set k11;
        Set h11;
        Set k12;
        Set h12;
        Set k13;
        Set h13;
        Set k14;
        Set h14;
        Set i10;
        Set l10;
        x02 = c0.x0(new jn.c('A', 'Z'), new jn.c('a', 'z'));
        X0 = c0.X0(x02);
        f16823i = X0;
        X02 = c0.X0(new jn.c('0', '9'));
        f16824j = X02;
        k10 = y0.k(X0, X02);
        h10 = x0.h('-', '.', '_', '~');
        k11 = y0.k(k10, h10);
        f16825k = k11;
        h11 = x0.h('!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=');
        f16826l = h11;
        k12 = y0.k(k11, h11);
        f16827m = k12;
        h12 = x0.h(':', '@');
        k13 = y0.k(k12, h12);
        f16828n = k13;
        h13 = x0.h(Character.valueOf(JsonPointer.SEPARATOR), '?');
        k14 = y0.k(k13, h13);
        f16829o = k14;
        h14 = x0.h('&', '=');
        i10 = y0.i(k14, h14);
        f16830p = i10;
        f16831q = k11;
        f16832r = k11;
        l10 = y0.l(k11, ':');
        f16833s = new d("host", l10, null, 4, null);
        f16834t = new d("user info", k12, null, 4, null);
        f16835u = new d("path", k13, null, 4, null);
        f16836v = new d("query string", i10, null, 4, null);
        f16837w = new d("fragment", k14, null, 4, null == true ? 1 : 0);
        Map map = null;
        int i11 = 4;
        k kVar = null;
        f16838x = new d("form URL", k11, map, i11, kVar);
        f16839y = new d("Smithy label", k11, map, i11, kVar);
        f16840z = new d("SigV4", k11, map, i11, kVar);
    }

    public d(String name, Set validChars, Map specialMapping) {
        i q10;
        int v10;
        int v11;
        int d10;
        int d11;
        int d12;
        Map o10;
        int v12;
        int d13;
        int d14;
        Map o11;
        int v13;
        int d15;
        int d16;
        t.g(name, "name");
        t.g(validChars, "validChars");
        t.g(specialMapping, "specialMapping");
        this.f16841b = name;
        this.f16842c = validChars;
        this.f16843d = specialMapping;
        q10 = o.q(0, 128);
        v10 = v.v(q10, 10);
        ArrayList arrayList = new ArrayList(v10);
        Iterator it = q10.iterator();
        while (it.hasNext()) {
            arrayList.add(Character.valueOf((char) ((k0) it).a()));
        }
        Set set = this.f16842c;
        ArrayList arrayList2 = new ArrayList();
        for (Object obj : arrayList) {
            if (!set.contains(Character.valueOf(((Character) obj).charValue()))) {
                arrayList2.add(obj);
            }
        }
        a aVar = f16822h;
        v11 = v.v(arrayList2, 10);
        d10 = p0.d(v11);
        d11 = o.d(d10, 16);
        LinkedHashMap linkedHashMap = new LinkedHashMap(d11);
        for (Object obj2 : arrayList2) {
            linkedHashMap.put(obj2, aVar.i(((Character) obj2).charValue()));
        }
        this.f16844e = linkedHashMap;
        Map map = this.f16843d;
        d12 = p0.d(map.size());
        LinkedHashMap linkedHashMap2 = new LinkedHashMap(d12);
        for (Map.Entry entry : map.entrySet()) {
            linkedHashMap2.put(entry.getKey(), String.valueOf(((Character) entry.getValue()).charValue()));
        }
        o10 = q0.o(linkedHashMap, linkedHashMap2);
        this.f16845f = o10;
        Set set2 = this.f16842c;
        v12 = v.v(set2, 10);
        d13 = p0.d(v12);
        d14 = o.d(d13, 16);
        LinkedHashMap linkedHashMap3 = new LinkedHashMap(d14);
        for (Object obj3 : set2) {
            linkedHashMap3.put(obj3, Character.valueOf(((Character) obj3).charValue()));
        }
        o11 = q0.o(linkedHashMap3, this.f16843d);
        Set<Map.Entry> entrySet = o11.entrySet();
        v13 = v.v(entrySet, 10);
        d15 = p0.d(v13);
        d16 = o.d(d15, 16);
        LinkedHashMap linkedHashMap4 = new LinkedHashMap(d16);
        for (Map.Entry entry2 : entrySet) {
            rm.v a10 = rm.c0.a(Character.valueOf(((Character) entry2.getValue()).charValue()), Character.valueOf(((Character) entry2.getKey()).charValue()));
            linkedHashMap4.put(a10.c(), a10.d());
        }
        this.f16846g = linkedHashMap4;
    }

    @Override // e7.b
    public String c(String encoded) {
        String v10;
        Integer n10;
        t.g(encoded, "encoded");
        StringBuilder sb2 = new StringBuilder(encoded.length());
        byte[] bArr = null;
        int i10 = 0;
        while (i10 < encoded.length()) {
            char charAt = encoded.charAt(i10);
            if (charAt == '%') {
                if (bArr == null) {
                    bArr = new byte[(encoded.length() - i10) / 3];
                }
                int i11 = 0;
                while (i10 + 2 < encoded.length() && charAt == '%') {
                    int i12 = i10 + 3;
                    String substring = encoded.substring(i10 + 1, i12);
                    t.f(substring, "substring(...)");
                    n10 = x.n(substring, 16);
                    if (n10 == null) {
                        break;
                    }
                    byte intValue = (byte) n10.intValue();
                    int i13 = i11 + 1;
                    bArr[i11] = intValue;
                    if (i12 < encoded.length()) {
                        charAt = encoded.charAt(i12);
                    }
                    i11 = i13;
                    i10 = i12;
                }
                v10 = y.v(bArr, 0, i11, false, 5, null);
                sb2.append(v10);
                if (i10 != encoded.length() && charAt == '%') {
                    sb2.append(charAt);
                }
            } else {
                Character ch2 = (Character) this.f16846g.get(Character.valueOf(charAt));
                if (ch2 != null) {
                    charAt = ch2.charValue();
                }
                sb2.append(charAt);
            }
            i10++;
        }
        String sb3 = sb2.toString();
        t.f(sb3, "toString(...)");
        return sb3;
    }

    @Override // e7.b
    public String d(String decoded) {
        byte[] w10;
        StringBuilder sb2;
        t.g(decoded, "decoded");
        StringBuilder sb3 = new StringBuilder(decoded.length());
        w10 = y.w(decoded);
        for (byte b10 : w10) {
            char c10 = (char) b10;
            if (this.f16842c.contains(Character.valueOf(c10))) {
                sb3.append(c10);
            } else {
                String str = (String) this.f16845f.get(Character.valueOf(c10));
                if (str != null) {
                    sb3.append(str);
                    sb2 = sb3;
                } else {
                    sb2 = null;
                }
                if (sb2 == null) {
                    f16822h.j(sb3, b10);
                } else {
                    t.d(sb2);
                }
            }
        }
        String sb4 = sb3.toString();
        t.f(sb4, "toString(...)");
        return sb4;
    }

    @Override // e7.b
    public e7.a e(String str) {
        return b.C0367b.a(this, str);
    }

    @Override // e7.b
    public e7.a f(String str) {
        return b.C0367b.b(this, str);
    }

    @Override // e7.b
    public String getName() {
        return this.f16841b;
    }

    public /* synthetic */ d(String str, Set set, Map map, int i10, k kVar) {
        this(str, set, (i10 & 4) != 0 ? q0.i() : map);
    }
}
