package kotlin.reflect.w.internal.y0.i;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import kotlin.reflect.w.internal.y0.i.a;
import kotlin.reflect.w.internal.y0.i.g;
import kotlin.reflect.w.internal.y0.i.i;
import kotlin.reflect.w.internal.y0.i.k;
import kotlin.reflect.w.internal.y0.i.p;
import kotlin.reflect.w.internal.y0.i.u;

/* JADX INFO: loaded from: classes2.dex */
public abstract class h extends kotlin.reflect.w.internal.y0.i.a implements Serializable {

    public static abstract class b<MessageType extends h, BuilderType extends b> extends a.AbstractC0155a<BuilderType> {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public kotlin.reflect.w.internal.y0.i.c f8259f = kotlin.reflect.w.internal.y0.i.c.f8234f;

        @Override // 
        /* JADX INFO: renamed from: k, reason: merged with bridge method [inline-methods] */
        public BuilderType clone() {
            throw new UnsupportedOperationException("This is supposed to be overridden by subclasses.");
        }

        public abstract BuilderType l(MessageType messagetype);
    }

    public static abstract class c<MessageType extends d<MessageType>, BuilderType extends c<MessageType, BuilderType>> extends b<MessageType, BuilderType> implements q {

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public g<e> f8260m = g.a;

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

        /* JADX WARN: Multi-variable type inference failed */
        /* JADX WARN: Type inference fix 'apply assigned field type' failed
        java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
        	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
        	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
        	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
         */
        public final void m(MessageType messagetype) {
            if (!this.f8261n) {
                this.f8260m = this.f8260m.clone();
                this.f8261n = true;
            }
            g<e> gVar = this.f8260m;
            g<e> gVar2 = messagetype.f8262f;
            Objects.requireNonNull(gVar);
            for (int i2 = 0; i2 < gVar2.f8256b.e(); i2++) {
                gVar.j(gVar2.f8256b.d(i2));
            }
            Iterator it = gVar2.f8256b.f().iterator();
            while (it.hasNext()) {
                gVar.j((Map.Entry) it.next());
            }
        }
    }

    public static final class e implements g.a<e> {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public final i.b<?> f8266f;

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public final int f8267m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public final y f8268n;

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

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

        public e(i.b<?> bVar, int i2, y yVar, boolean z2, boolean z3) {
            this.f8266f = bVar;
            this.f8267m = i2;
            this.f8268n = yVar;
            this.f8269o = z2;
            this.f8270p = z3;
        }

        @Override // r.i0.w.b.y0.i.g.a
        public int a() {
            return this.f8267m;
        }

        @Override // r.i0.w.b.y0.i.g.a
        public p.a c(p.a aVar, p pVar) {
            return ((b) aVar).l((h) pVar);
        }

        @Override // java.lang.Comparable
        public int compareTo(Object obj) {
            return this.f8267m - ((e) obj).f8267m;
        }

        @Override // r.i0.w.b.y0.i.g.a
        public boolean d() {
            return this.f8269o;
        }

        @Override // r.i0.w.b.y0.i.g.a
        public y f() {
            return this.f8268n;
        }

        @Override // r.i0.w.b.y0.i.g.a
        public z n() {
            return this.f8268n.E;
        }

        @Override // r.i0.w.b.y0.i.g.a
        public boolean p() {
            return this.f8270p;
        }
    }

    public static class f<ContainingType extends p, Type> {
        public final ContainingType a;

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

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

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public final e f8273d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public final Method f8274e;

        public f(ContainingType containingtype, Type type, p pVar, e eVar, Class cls) {
            Method method;
            if (containingtype == null) {
                throw new IllegalArgumentException("Null containingTypeDefaultInstance");
            }
            if (eVar.f8268n == y.f8329v && pVar == null) {
                throw new IllegalArgumentException("Null messageDefaultInstance");
            }
            this.a = containingtype;
            this.f8271b = type;
            this.f8272c = pVar;
            this.f8273d = eVar;
            if (i.a.class.isAssignableFrom(cls)) {
                try {
                    method = cls.getMethod("valueOf", Integer.TYPE);
                } catch (NoSuchMethodException e2) {
                    String name = cls.getName();
                    StringBuilder sb = new StringBuilder(7 + name.length() + 45);
                    sb.append("Generated message class \"");
                    sb.append(name);
                    sb.append("\" missing method \"");
                    sb.append("valueOf");
                    sb.append("\".");
                    throw new RuntimeException(sb.toString(), e2);
                }
            } else {
                method = null;
            }
            this.f8274e = method;
        }

        public Object a(Object obj) {
            if (this.f8273d.f8268n.E != z.ENUM) {
                return obj;
            }
            try {
                return this.f8274e.invoke(null, (Integer) obj);
            } catch (IllegalAccessException e2) {
                throw new RuntimeException("Couldn't use Java reflection to implement protocol message reflection.", e2);
            } catch (InvocationTargetException e3) {
                Throwable cause = e3.getCause();
                if (cause instanceof RuntimeException) {
                    throw ((RuntimeException) cause);
                }
                if (cause instanceof Error) {
                    throw ((Error) cause);
                }
                throw new RuntimeException("Unexpected exception thrown by generated accessor method.", cause);
            }
        }

        public Object b(Object obj) {
            return this.f8273d.f8268n.E == z.ENUM ? Integer.valueOf(((i.a) obj).a()) : obj;
        }
    }

    public h() {
    }

    public h(b bVar) {
    }

    public static <ContainingType extends p, Type> f<ContainingType, Type> e(ContainingType containingtype, p pVar, i.b<?> bVar, int i2, y yVar, boolean z2, Class cls) {
        return new f<>(containingtype, Collections.emptyList(), pVar, new e(null, i2, yVar, true, z2), cls);
    }

    public static <ContainingType extends p, Type> f<ContainingType, Type> j(ContainingType containingtype, Type type, p pVar, i.b<?> bVar, int i2, y yVar, Class cls) {
        return new f<>(containingtype, type, pVar, new e(null, i2, yVar, false, false), cls);
    }

    public static abstract class d<MessageType extends d<MessageType>> extends h implements q {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public final g<e> f8262f;

        public class a {
            public final Iterator<Map.Entry<e, Object>> a;

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public Map.Entry<e, Object> f8263b;

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

            public a(boolean z2, a aVar) {
                g<e> gVar = d.this.f8262f;
                Iterator<Map.Entry<e, Object>> cVar = gVar.f8258d ? new k.c<>(((u.d) gVar.f8256b.entrySet()).iterator()) : ((u.d) gVar.f8256b.entrySet()).iterator();
                this.a = cVar;
                if (cVar.hasNext()) {
                    this.f8263b = cVar.next();
                }
                this.f8264c = z2;
            }

            public void a(int i2, kotlin.reflect.w.internal.y0.i.e eVar) {
                while (true) {
                    Map.Entry<e, Object> entry = this.f8263b;
                    if (entry == null || entry.getKey().f8267m >= i2) {
                        return;
                    }
                    e key = this.f8263b.getKey();
                    if (this.f8264c && key.f8268n.E == z.MESSAGE && !key.f8269o) {
                        int i3 = key.f8267m;
                        p pVar = (p) this.f8263b.getValue();
                        eVar.A(1, 3);
                        eVar.y(16);
                        eVar.y(i3);
                        eVar.r(3, pVar);
                        eVar.A(1, 4);
                    } else {
                        Object value = this.f8263b.getValue();
                        g gVar = g.a;
                        y yVarF = key.f();
                        int iA = key.a();
                        if (key.d()) {
                            List list = (List) value;
                            if (key.p()) {
                                eVar.A(iA, 2);
                                int iD = 0;
                                Iterator it = list.iterator();
                                while (it.hasNext()) {
                                    iD += g.d(yVarF, it.next());
                                }
                                eVar.y(iD);
                                Iterator it2 = list.iterator();
                                while (it2.hasNext()) {
                                    g.o(eVar, yVarF, it2.next());
                                }
                            } else {
                                Iterator it3 = list.iterator();
                                while (it3.hasNext()) {
                                    g.n(eVar, yVarF, iA, it3.next());
                                }
                            }
                        } else if (value instanceof k) {
                            g.n(eVar, yVarF, iA, ((k) value).a());
                        } else {
                            g.n(eVar, yVarF, iA, value);
                        }
                    }
                    this.f8263b = this.a.hasNext() ? this.a.next() : null;
                }
            }
        }

        public d() {
            this.f8262f = new g<>();
        }

        /* JADX WARN: Multi-variable type inference failed */
        /* JADX WARN: Type inference fix 'apply assigned field type' failed
        java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
        	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
        	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
        	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
         */
        public boolean k() {
            g<e> gVar = this.f8262f;
            for (int i2 = 0; i2 < gVar.f8256b.e(); i2++) {
                if (!gVar.h(gVar.f8256b.d(i2))) {
                    return false;
                }
            }
            Iterator it = gVar.f8256b.f().iterator();
            while (it.hasNext()) {
                if (!gVar.h((Map.Entry) it.next())) {
                    return false;
                }
            }
            return true;
        }

        /* JADX WARN: Type inference fix 'apply assigned field type' failed
        java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
        	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
        	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
        	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
        	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
         */
        public int l() {
            g<e> gVar = this.f8262f;
            int iE = 0;
            for (int i2 = 0; i2 < gVar.f8256b.e(); i2++) {
                Map.Entry entryD = gVar.f8256b.d(i2);
                iE += g.e((g.a) entryD.getKey(), entryD.getValue());
            }
            for (Map.Entry entry : gVar.f8256b.f()) {
                iE += g.e((g.a) entry.getKey(), entry.getValue());
            }
            return iE;
        }

        /* JADX WARN: Multi-variable type inference failed */
        /* JADX WARN: Type inference failed for: r1v4, types: [Type, java.util.ArrayList] */
        public final <Type> Type m(f<MessageType, Type> fVar) {
            r(fVar);
            Type type = (Type) this.f8262f.f(fVar.f8273d);
            if (type == null) {
                return fVar.f8271b;
            }
            e eVar = fVar.f8273d;
            if (!eVar.f8269o) {
                return (Type) fVar.a(type);
            }
            if (eVar.f8268n.E != z.ENUM) {
                return type;
            }
            ?? r1 = (Type) new ArrayList();
            Iterator it = ((List) type).iterator();
            while (it.hasNext()) {
                r1.add(fVar.a(it.next()));
            }
            return r1;
        }

        /* JADX WARN: Multi-variable type inference failed */
        public final <Type> boolean n(f<MessageType, Type> fVar) {
            r(fVar);
            g<e> gVar = this.f8262f;
            e eVar = fVar.f8273d;
            Objects.requireNonNull(gVar);
            if (eVar.d()) {
                throw new IllegalArgumentException("hasField() can only be called on non-repeated fields.");
            }
            return gVar.f8256b.get(eVar) != null;
        }

        public void o() {
            this.f8262f.i();
        }

        public d<MessageType>.a p() {
            return new a(false, null);
        }

        /* JADX WARN: Removed duplicated region for block: B:15:0x0044  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public boolean q(kotlin.reflect.w.internal.y0.i.d r8, kotlin.reflect.w.internal.y0.i.e r9, kotlin.reflect.w.internal.y0.i.f r10, int r11) throws kotlin.reflect.w.internal.y0.i.j {
            /*
                Method dump skipped, instruction units count: 334
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: r.i0.w.b.y0.i.h.d.q(r.i0.w.b.y0.i.d, r.i0.w.b.y0.i.e, r.i0.w.b.y0.i.f, int):boolean");
        }

        public final void r(f<MessageType, ?> fVar) {
            if (fVar.a != b()) {
                throw new IllegalArgumentException("This extension is for a different message type.  Please make sure that you are not suppressing any generics type warnings.");
            }
        }

        public d(c<MessageType, ?> cVar) {
            cVar.f8260m.i();
            cVar.f8261n = false;
            this.f8262f = cVar.f8260m;
        }
    }
}
