package defpackage;

import android.util.Base64;
import android.util.JsonWriter;
import com.google.firebase.encoders.EncodingException;
import java.io.IOException;
import java.io.Writer;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/* JADX INFO: renamed from: ᵯᵾ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4332 implements InterfaceC4364, InterfaceC1815 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final JsonWriter f16495;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final Map f16496;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final InterfaceC2474 f16497;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final boolean f16498 = true;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final Map f16499;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final boolean f16500;

    public C4332(Writer writer, HashMap map, HashMap map2, C2582 c2582, boolean z) {
        this.f16495 = new JsonWriter(writer);
        this.f16496 = map;
        this.f16499 = map2;
        this.f16497 = c2582;
        this.f16500 = z;
    }

    @Override // defpackage.InterfaceC1815
    /* JADX INFO: renamed from: ʽˈˋ */
    public final InterfaceC1815 mo4980(String str) throws IOException {
        m9320();
        this.f16495.value(str);
        return this;
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final C4332 m9319(Object obj) throws IOException {
        JsonWriter jsonWriter = this.f16495;
        if (obj == null) {
            jsonWriter.nullValue();
            return this;
        }
        if (obj instanceof Number) {
            jsonWriter.value((Number) obj);
            return this;
        }
        int i = 0;
        if (!obj.getClass().isArray()) {
            if (obj instanceof Collection) {
                jsonWriter.beginArray();
                Iterator it = ((Collection) obj).iterator();
                while (it.hasNext()) {
                    m9319(it.next());
                }
                jsonWriter.endArray();
                return this;
            }
            if (obj instanceof Map) {
                jsonWriter.beginObject();
                for (Map.Entry entry : ((Map) obj).entrySet()) {
                    Object key = entry.getKey();
                    try {
                        m9321(entry.getValue(), (String) key);
                    } catch (ClassCastException e) {
                        throw new EncodingException(String.format("Only String keys are currently supported in maps, got %s of type %s instead.", key, key.getClass()), e);
                    }
                }
                jsonWriter.endObject();
                return this;
            }
            InterfaceC2474 interfaceC2474 = (InterfaceC2474) this.f16496.get(obj.getClass());
            if (interfaceC2474 != null) {
                jsonWriter.beginObject();
                interfaceC2474.mo1073(obj, this);
                jsonWriter.endObject();
                return this;
            }
            InterfaceC4429 interfaceC4429 = (InterfaceC4429) this.f16499.get(obj.getClass());
            if (interfaceC4429 != null) {
                interfaceC4429.mo1073(obj, this);
                return this;
            }
            if (!(obj instanceof Enum)) {
                jsonWriter.beginObject();
                this.f16497.mo1073(obj, this);
                jsonWriter.endObject();
                return this;
            }
            if (obj instanceof InterfaceC1099) {
                int iMo1949 = ((InterfaceC1099) obj).mo1949();
                m9320();
                jsonWriter.value(iMo1949);
                return this;
            }
            String strName = ((Enum) obj).name();
            m9320();
            jsonWriter.value(strName);
            return this;
        }
        if (obj instanceof byte[]) {
            m9320();
            jsonWriter.value(Base64.encodeToString((byte[]) obj, 2));
            return this;
        }
        jsonWriter.beginArray();
        if (obj instanceof int[]) {
            int length = ((int[]) obj).length;
            while (i < length) {
                jsonWriter.value(r7[i]);
                i++;
            }
        } else if (obj instanceof long[]) {
            long[] jArr = (long[]) obj;
            int length2 = jArr.length;
            while (i < length2) {
                long j = jArr[i];
                m9320();
                jsonWriter.value(j);
                i++;
            }
        } else if (obj instanceof double[]) {
            double[] dArr = (double[]) obj;
            int length3 = dArr.length;
            while (i < length3) {
                jsonWriter.value(dArr[i]);
                i++;
            }
        } else if (obj instanceof boolean[]) {
            boolean[] zArr = (boolean[]) obj;
            int length4 = zArr.length;
            while (i < length4) {
                jsonWriter.value(zArr[i]);
                i++;
            }
        } else if (obj instanceof Number[]) {
            Number[] numberArr = (Number[]) obj;
            int length5 = numberArr.length;
            while (i < length5) {
                m9319(numberArr[i]);
                i++;
            }
        } else {
            Object[] objArr = (Object[]) obj;
            int length6 = objArr.length;
            while (i < length6) {
                m9319(objArr[i]);
                i++;
            }
        }
        jsonWriter.endArray();
        return this;
    }

    @Override // defpackage.InterfaceC1815
    /* JADX INFO: renamed from: ːˏᵟᵯ */
    public final InterfaceC1815 mo4981(boolean z) throws IOException {
        m9320();
        this.f16495.value(z);
        return this;
    }

    @Override // defpackage.InterfaceC4364
    /* JADX INFO: renamed from: ᵨᵣ */
    public final InterfaceC4364 mo8607(C3961 c3961, int i) throws IOException {
        String str = c3961.f15130;
        m9320();
        JsonWriter jsonWriter = this.f16495;
        jsonWriter.name(str);
        m9320();
        jsonWriter.value(i);
        return this;
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final void m9320() {
        if (this.f16498) {
            return;
        }
        ᵕᵩʽᵲ.ᵪᵹᵥᵻ("Parent context used since this context was created. Cannot use this context anymore.");
    }

    @Override // defpackage.InterfaceC4364
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final InterfaceC4364 mo8610(C3961 c3961, Object obj) throws IOException {
        m9321(obj, c3961.f15130);
        return this;
    }

    @Override // defpackage.InterfaceC4364
    /* JADX INFO: renamed from: ᵵᵽ */
    public final InterfaceC4364 mo8611(C3961 c3961, long j) throws IOException {
        String str = c3961.f15130;
        m9320();
        JsonWriter jsonWriter = this.f16495;
        jsonWriter.name(str);
        m9320();
        jsonWriter.value(j);
        return this;
    }

    @Override // defpackage.InterfaceC4364
    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    public final InterfaceC4364 mo8612(C3961 c3961, boolean z) throws IOException {
        String str = c3961.f15130;
        m9320();
        JsonWriter jsonWriter = this.f16495;
        jsonWriter.name(str);
        m9320();
        jsonWriter.value(z);
        return this;
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final C4332 m9321(Object obj, String str) throws IOException {
        boolean z = this.f16500;
        JsonWriter jsonWriter = this.f16495;
        if (z) {
            if (obj == null) {
                return this;
            }
            m9320();
            jsonWriter.name(str);
            m9319(obj);
            return this;
        }
        m9320();
        jsonWriter.name(str);
        if (obj == null) {
            jsonWriter.nullValue();
            return this;
        }
        m9319(obj);
        return this;
    }

    @Override // defpackage.InterfaceC4364
    /* JADX INFO: renamed from: ᵻˈᵦʼ */
    public final InterfaceC4364 mo8614(C3961 c3961, double d) throws IOException {
        String str = c3961.f15130;
        m9320();
        JsonWriter jsonWriter = this.f16495;
        jsonWriter.name(str);
        m9320();
        jsonWriter.value(d);
        return this;
    }
}
