package F3;

import A2.j;
import A2.p;
import F2.Z;
import F2.f0;
import F2.r0;
import K4.m;
import K4.o;
import L1.C0105i0;
import a.AbstractC0212a;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.WorkSource;
import android.text.TextUtils;
import android.util.Log;
import androidx.recyclerview.widget.RecyclerView;
import c1.InterfaceC0336b;
import c4.InterfaceC0342a;
import com.google.android.gms.location.LocationRequest;
import com.google.firebase.messaging.w;
import d4.C0545d;
import e4.AbstractC0566j;
import f1.C0590a;
import i1.InterfaceC0623c;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import r4.AbstractC0983h;
import t2.k;
import t2.l;
import u0.C1039a;
import u0.C1061x;
import u2.h;

/* JADX INFO: loaded from: classes.dex */
public final class e implements InterfaceC0336b {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ int f713k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public Object f714l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public Object f715m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public Object f716n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public Object f717o;
    public Object p;

    public /* synthetic */ e() {
        this.f713k = 8;
    }

    public static e e(SharedPreferences sharedPreferences, ScheduledThreadPoolExecutor scheduledThreadPoolExecutor) {
        e eVar = new e(sharedPreferences, scheduledThreadPoolExecutor);
        synchronized (((ArrayDeque) eVar.f717o)) {
            try {
                ((ArrayDeque) eVar.f717o).clear();
                String string = ((SharedPreferences) eVar.f714l).getString((String) eVar.f715m, "");
                if (!TextUtils.isEmpty(string) && string.contains((String) eVar.f716n)) {
                    String[] strArrSplit = string.split((String) eVar.f716n, -1);
                    if (strArrSplit.length == 0) {
                        Log.e("FirebaseMessaging", "Corrupted queue. Please check the queue contents and item separator provided");
                    }
                    for (String str : strArrSplit) {
                        if (!TextUtils.isEmpty(str)) {
                            ((ArrayDeque) eVar.f717o).add(str);
                        }
                    }
                    return eVar;
                }
                return eVar;
            } finally {
            }
        }
    }

    public void a(Object obj, Object obj2, f0 f0Var, boolean z5) {
        byte[] bArrArray;
        if (((ConcurrentHashMap) this.f715m) == null) {
            throw new IllegalStateException("addPrimitive cannot be called after build");
        }
        if (obj == null && obj2 == null) {
            throw new GeneralSecurityException("at least one of the `fullPrimitive` or `primitive` must be set");
        }
        if (f0Var.D() != Z.ENABLED) {
            throw new GeneralSecurityException("only ENABLED key is allowed");
        }
        Integer numValueOf = Integer.valueOf(f0Var.B());
        if (f0Var.C() == r0.RAW) {
            numValueOf = null;
        }
        t2.b bVarA = j.f38b.a(p.i(f0Var.A().B(), f0Var.A().C(), f0Var.A().A(), f0Var.C(), numValueOf));
        int iOrdinal = f0Var.C().ordinal();
        if (iOrdinal == 1) {
            bArrArray = ByteBuffer.allocate(5).put((byte) 1).putInt(f0Var.B()).array();
        } else if (iOrdinal == 2) {
            bArrArray = ByteBuffer.allocate(5).put((byte) 0).putInt(f0Var.B()).array();
        } else if (iOrdinal != 3) {
            if (iOrdinal != 4) {
                throw new GeneralSecurityException("unknown output prefix type");
            }
            bArrArray = ByteBuffer.allocate(5).put((byte) 0).putInt(f0Var.B()).array();
        } else {
            bArrArray = t2.b.f9976a;
        }
        k kVar = new k(obj, obj2, bArrArray, f0Var.D(), f0Var.C(), f0Var.B(), f0Var.A().B(), bVarA);
        ConcurrentHashMap concurrentHashMap = (ConcurrentHashMap) this.f715m;
        ArrayList arrayList = (ArrayList) this.f716n;
        ArrayList arrayList2 = new ArrayList();
        arrayList2.add(kVar);
        byte[] bArr = kVar.f9990c;
        l lVar = new l(bArr != null ? Arrays.copyOf(bArr, bArr.length) : null);
        List list = (List) concurrentHashMap.put(lVar, Collections.unmodifiableList(arrayList2));
        if (list != null) {
            ArrayList arrayList3 = new ArrayList();
            arrayList3.addAll(list);
            arrayList3.add(kVar);
            concurrentHashMap.put(lVar, Collections.unmodifiableList(arrayList3));
        }
        arrayList.add(kVar);
        if (z5) {
            if (((k) this.f717o) != null) {
                throw new IllegalStateException("you cannot set two primary primitives");
            }
            this.f717o = kVar;
        }
    }

    public h b() throws GeneralSecurityException {
        if (((Integer) this.f714l) == null) {
            throw new GeneralSecurityException("AES key size is not set");
        }
        if (((Integer) this.f715m) == null) {
            throw new GeneralSecurityException("HMAC key size is not set");
        }
        Integer num = (Integer) this.f716n;
        if (num == null) {
            throw new GeneralSecurityException("tag size is not set");
        }
        if (((u2.g) this.f717o) == null) {
            throw new GeneralSecurityException("hash type is not set");
        }
        if (((u2.g) this.p) == null) {
            throw new GeneralSecurityException("variant is not set");
        }
        int iIntValue = num.intValue();
        u2.g gVar = (u2.g) this.f717o;
        if (gVar == u2.g.f10318c) {
            if (iIntValue > 20) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 20 bytes for SHA1", num));
            }
        } else if (gVar == u2.g.f10319d) {
            if (iIntValue > 28) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 28 bytes for SHA224", num));
            }
        } else if (gVar == u2.g.f10320e) {
            if (iIntValue > 32) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 32 bytes for SHA256", num));
            }
        } else if (gVar == u2.g.f10321f) {
            if (iIntValue > 48) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 48 bytes for SHA384", num));
            }
        } else {
            if (gVar != u2.g.f10322g) {
                throw new GeneralSecurityException("unknown hash type; must be SHA1, SHA224, SHA256, SHA384 or SHA512");
            }
            if (iIntValue > 64) {
                throw new GeneralSecurityException(String.format("Invalid tag size in bytes %d; can be at most 64 bytes for SHA512", num));
            }
        }
        return new h(((Integer) this.f714l).intValue(), ((Integer) this.f715m).intValue(), ((Integer) this.f716n).intValue(), (u2.g) this.p, (u2.g) this.f717o);
    }

    public boolean c(int i) {
        ArrayList arrayList = (ArrayList) this.f716n;
        int size = arrayList.size();
        for (int i5 = 0; i5 < size; i5++) {
            C1039a c1039a = (C1039a) arrayList.get(i5);
            int i6 = c1039a.f10146a;
            if (i6 != 8) {
                if (i6 == 1) {
                    int i7 = c1039a.f10147b;
                    int i8 = c1039a.f10148c + i7;
                    while (i7 < i8) {
                        if (h(i7, i5 + 1) == i) {
                            return true;
                        }
                        i7++;
                    }
                } else {
                    continue;
                }
            } else {
                if (h(c1039a.f10148c, i5 + 1) == i) {
                    return true;
                }
            }
        }
        return false;
    }

    public void d() {
        ArrayList arrayList = (ArrayList) this.f716n;
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            ((C1061x) this.f717o).a((C1039a) arrayList.get(i));
        }
        m(arrayList);
        ArrayList arrayList2 = (ArrayList) this.f715m;
        int size2 = arrayList2.size();
        for (int i5 = 0; i5 < size2; i5++) {
            C1039a c1039a = (C1039a) arrayList2.get(i5);
            int i6 = c1039a.f10146a;
            C1061x c1061x = (C1061x) this.f717o;
            if (i6 == 1) {
                c1061x.a(c1039a);
                c1061x.d(c1039a.f10147b, c1039a.f10148c);
            } else if (i6 == 2) {
                c1061x.a(c1039a);
                int i7 = c1039a.f10147b;
                int i8 = c1039a.f10148c;
                RecyclerView recyclerView = c1061x.f10308a;
                recyclerView.N(i7, true, i8);
                recyclerView.f4578p0 = true;
                recyclerView.f4573m0.f10101c += i8;
            } else if (i6 == 4) {
                c1061x.a(c1039a);
                c1061x.c(c1039a.f10147b, c1039a.f10148c);
            } else if (i6 == 8) {
                c1061x.a(c1039a);
                c1061x.e(c1039a.f10147b, c1039a.f10148c);
            }
        }
        m(arrayList2);
    }

    public void f(C1039a c1039a) {
        int i;
        O.b bVar;
        int i5 = c1039a.f10146a;
        if (i5 == 1 || i5 == 8) {
            throw new IllegalArgumentException("should not dispatch add or move for pre layout");
        }
        int iN = n(c1039a.f10147b, i5);
        int i6 = c1039a.f10147b;
        int i7 = c1039a.f10146a;
        if (i7 == 2) {
            i = 0;
        } else {
            if (i7 != 4) {
                throw new IllegalArgumentException("op should be remove or update." + c1039a);
            }
            i = 1;
        }
        int i8 = 1;
        int i9 = 1;
        while (true) {
            int i10 = c1039a.f10148c;
            bVar = (O.b) this.f714l;
            if (i8 >= i10) {
                break;
            }
            int iN2 = n((i * i8) + c1039a.f10147b, c1039a.f10146a);
            int i11 = c1039a.f10146a;
            if (i11 == 2 ? iN2 != iN : !(i11 == 4 && iN2 == iN + 1)) {
                C1039a c1039aK = k(i11, iN, i9);
                g(c1039aK, i6);
                bVar.c(c1039aK);
                if (c1039a.f10146a == 4) {
                    i6 += i9;
                }
                i9 = 1;
                iN = iN2;
            } else {
                i9++;
            }
            i8++;
        }
        bVar.c(c1039a);
        if (i9 > 0) {
            C1039a c1039aK2 = k(c1039a.f10146a, iN, i9);
            g(c1039aK2, i6);
            bVar.c(c1039aK2);
        }
    }

    public void g(C1039a c1039a, int i) {
        C1061x c1061x = (C1061x) this.f717o;
        c1061x.a(c1039a);
        int i5 = c1039a.f10146a;
        if (i5 != 2) {
            if (i5 != 4) {
                throw new IllegalArgumentException("only remove and update ops can be dispatched in first pass");
            }
            c1061x.c(i, c1039a.f10148c);
        } else {
            int i6 = c1039a.f10148c;
            RecyclerView recyclerView = c1061x.f10308a;
            recyclerView.N(i, true, i6);
            recyclerView.f4578p0 = true;
            recyclerView.f4573m0.f10101c += i6;
        }
    }

    @Override // c4.InterfaceC0342a
    public Object get() {
        return new C0590a((Executor) ((InterfaceC0342a) this.f714l).get(), (b1.f) ((InterfaceC0342a) this.f715m).get(), (g1.d) ((B2.a) this.f716n).get(), (h1.d) ((InterfaceC0342a) this.f717o).get(), (InterfaceC0623c) ((InterfaceC0342a) this.p).get());
    }

    public int h(int i, int i5) {
        ArrayList arrayList = (ArrayList) this.f716n;
        int size = arrayList.size();
        while (i5 < size) {
            C1039a c1039a = (C1039a) arrayList.get(i5);
            int i6 = c1039a.f10146a;
            if (i6 == 8) {
                int i7 = c1039a.f10147b;
                if (i7 == i) {
                    i = c1039a.f10148c;
                } else {
                    if (i7 < i) {
                        i--;
                    }
                    if (c1039a.f10148c <= i) {
                        i++;
                    }
                }
            } else {
                int i8 = c1039a.f10147b;
                if (i8 > i) {
                    continue;
                } else if (i6 == 2) {
                    int i9 = c1039a.f10148c;
                    if (i < i8 + i9) {
                        return -1;
                    }
                    i -= i9;
                } else if (i6 == 1) {
                    i += c1039a.f10148c;
                }
            }
            i5++;
        }
        return i;
    }

    public boolean i() {
        return ((ArrayList) this.f715m).size() > 0;
    }

    public w j() {
        w wVar = new w();
        wVar.f5946n = new LinkedHashMap();
        wVar.f5944l = (o) this.f714l;
        wVar.f5943k = (String) this.f715m;
        Map map = (Map) this.f717o;
        wVar.f5946n = map.isEmpty() ? new LinkedHashMap() : new LinkedHashMap(map);
        wVar.f5945m = ((m) this.f716n).c();
        return wVar;
    }

    public C1039a k(int i, int i5, int i6) {
        C1039a c1039a = (C1039a) ((O.b) this.f714l).a();
        if (c1039a != null) {
            c1039a.f10146a = i;
            c1039a.f10147b = i5;
            c1039a.f10148c = i6;
            return c1039a;
        }
        C1039a c1039a2 = new C1039a();
        c1039a2.f10146a = i;
        c1039a2.f10147b = i5;
        c1039a2.f10148c = i6;
        return c1039a2;
    }

    public void l(C1039a c1039a) {
        ((ArrayList) this.f716n).add(c1039a);
        int i = c1039a.f10146a;
        C1061x c1061x = (C1061x) this.f717o;
        if (i == 1) {
            c1061x.d(c1039a.f10147b, c1039a.f10148c);
            return;
        }
        if (i == 2) {
            int i5 = c1039a.f10147b;
            int i6 = c1039a.f10148c;
            RecyclerView recyclerView = c1061x.f10308a;
            recyclerView.N(i5, false, i6);
            recyclerView.f4578p0 = true;
            return;
        }
        if (i == 4) {
            c1061x.c(c1039a.f10147b, c1039a.f10148c);
        } else if (i == 8) {
            c1061x.e(c1039a.f10147b, c1039a.f10148c);
        } else {
            throw new IllegalArgumentException("Unknown update op type for " + c1039a);
        }
    }

    public void m(ArrayList arrayList) {
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            C1039a c1039a = (C1039a) arrayList.get(i);
            c1039a.getClass();
            ((O.b) this.f714l).c(c1039a);
        }
        arrayList.clear();
    }

    public int n(int i, int i5) {
        int i6;
        int i7;
        ArrayList arrayList = (ArrayList) this.f716n;
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            C1039a c1039a = (C1039a) arrayList.get(size);
            int i8 = c1039a.f10146a;
            if (i8 == 8) {
                int i9 = c1039a.f10147b;
                int i10 = c1039a.f10148c;
                if (i9 < i10) {
                    i7 = i9;
                    i6 = i10;
                } else {
                    i6 = i9;
                    i7 = i10;
                }
                if (i < i7 || i > i6) {
                    if (i < i9) {
                        if (i5 == 1) {
                            c1039a.f10147b = i9 + 1;
                            c1039a.f10148c = i10 + 1;
                        } else if (i5 == 2) {
                            c1039a.f10147b = i9 - 1;
                            c1039a.f10148c = i10 - 1;
                        }
                    }
                } else if (i7 == i9) {
                    if (i5 == 1) {
                        c1039a.f10148c = i10 + 1;
                    } else if (i5 == 2) {
                        c1039a.f10148c = i10 - 1;
                    }
                    i++;
                } else {
                    if (i5 == 1) {
                        c1039a.f10147b = i9 + 1;
                    } else if (i5 == 2) {
                        c1039a.f10147b = i9 - 1;
                    }
                    i--;
                }
            } else {
                int i11 = c1039a.f10147b;
                if (i11 <= i) {
                    if (i8 == 1) {
                        i -= c1039a.f10148c;
                    } else if (i8 == 2) {
                        i += c1039a.f10148c;
                    }
                } else if (i5 == 1) {
                    c1039a.f10147b = i11 + 1;
                } else if (i5 == 2) {
                    c1039a.f10147b = i11 - 1;
                }
            }
        }
        for (int size2 = arrayList.size() - 1; size2 >= 0; size2--) {
            C1039a c1039a2 = (C1039a) arrayList.get(size2);
            int i12 = c1039a2.f10146a;
            O.b bVar = (O.b) this.f714l;
            if (i12 == 8) {
                int i13 = c1039a2.f10148c;
                if (i13 == c1039a2.f10147b || i13 < 0) {
                    arrayList.remove(size2);
                    bVar.c(c1039a2);
                }
            } else if (c1039a2.f10148c <= 0) {
                arrayList.remove(size2);
                bVar.c(c1039a2);
            }
        }
        return i;
    }

    public String toString() {
        switch (this.f713k) {
            case 1:
                StringBuilder sb = new StringBuilder("Request{method=");
                sb.append((String) this.f715m);
                sb.append(", url=");
                sb.append((o) this.f714l);
                m mVar = (m) this.f716n;
                if (mVar.size() != 0) {
                    sb.append(", headers=[");
                    int i = 0;
                    for (Object obj : mVar) {
                        int i5 = i + 1;
                        if (i < 0) {
                            AbstractC0566j.y();
                            throw null;
                        }
                        C0545d c0545d = (C0545d) obj;
                        String str = (String) c0545d.f6135k;
                        String str2 = (String) c0545d.f6136l;
                        if (i > 0) {
                            sb.append(", ");
                        }
                        sb.append(str);
                        sb.append(':');
                        sb.append(str2);
                        i = i5;
                    }
                    sb.append(']');
                }
                Map map = (Map) this.f717o;
                if (!map.isEmpty()) {
                    sb.append(", tags=");
                    sb.append(map);
                }
                sb.append('}');
                String string = sb.toString();
                AbstractC0983h.d("StringBuilder().apply(builderAction).toString()", string);
                return string;
            default:
                return super.toString();
        }
    }

    public /* synthetic */ e(Object obj, Object obj2, Object obj3, Object obj4, Object obj5, int i) {
        this.f713k = i;
        this.f714l = obj;
        this.f715m = obj2;
        this.f716n = obj3;
        this.f717o = obj4;
        this.p = obj5;
    }

    public e(c cVar, d dVar, a aVar, b bVar, Set set, Set set2) {
        this.f713k = 0;
        AbstractC0983h.e("pirate", cVar);
        AbstractC0983h.e("stores", dVar);
        AbstractC0983h.e("collateral", aVar);
        AbstractC0983h.e("custom", bVar);
        this.f714l = cVar;
        this.f715m = dVar;
        this.f716n = aVar;
        this.f717o = set;
        this.p = set2;
    }

    public e(o oVar, String str, m mVar, AbstractC0212a abstractC0212a, Map map) {
        this.f713k = 1;
        AbstractC0983h.e("url", oVar);
        AbstractC0983h.e("method", str);
        this.f714l = oVar;
        this.f715m = str;
        this.f716n = mVar;
        this.f717o = map;
    }

    public e(Context context, C0105i0 c0105i0) {
        this.f713k = 3;
        this.p = new V3.a(this);
        this.f714l = context;
        this.f715m = c0105i0;
        int i = I1.a.f910a;
        this.f716n = new F1.b(context, F1.b.i, q1.b.f9542a, q1.e.f9544b);
        LocationRequest locationRequest = new LocationRequest(102, 3600000L, 600000L, 0L, Long.MAX_VALUE, Long.MAX_VALUE, Integer.MAX_VALUE, 0.0f, true, 3600000L, 0, 0, false, new WorkSource(), null);
        this.f717o = locationRequest;
        I1.d.a(100);
        locationRequest.f5336k = 100;
        LocationRequest locationRequest2 = (LocationRequest) this.f717o;
        locationRequest2.getClass();
        long j5 = locationRequest2.f5338m;
        long j6 = locationRequest2.f5337l;
        if (j5 == j6 / 6) {
            locationRequest2.f5338m = 1666L;
        }
        if (locationRequest2.f5342s == j6) {
            locationRequest2.f5342s = 10000L;
        }
        locationRequest2.f5337l = 10000L;
        LocationRequest locationRequest3 = (LocationRequest) this.f717o;
        locationRequest3.getClass();
        locationRequest3.f5338m = 5000L;
    }

    public e(SharedPreferences sharedPreferences, ScheduledThreadPoolExecutor scheduledThreadPoolExecutor) {
        this.f713k = 4;
        this.f717o = new ArrayDeque();
        this.f714l = sharedPreferences;
        this.f715m = "topic_operation_queue";
        this.f716n = ",";
        this.p = scheduledThreadPoolExecutor;
    }

    public e(C1061x c1061x) {
        this.f713k = 7;
        this.f714l = new O.b(30);
        this.f715m = new ArrayList();
        this.f716n = new ArrayList();
        this.f717o = c1061x;
        this.p = new k3.g(this);
    }

    public e(Class cls) {
        this.f713k = 6;
        this.f715m = new ConcurrentHashMap();
        this.f716n = new ArrayList();
        this.f714l = cls;
        this.p = D2.a.f439b;
    }
}
