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;

/* renamed from: ˊˁᵝʔ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1290 implements InterfaceC4148, InterfaceC1302 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final InterfaceC3555 f5314;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final boolean f5315;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final Map f5316;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final boolean f5317 = true;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final JsonWriter f5318;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final Map f5319;

    public C1290(Writer writer, HashMap map, HashMap map2, C0962 c0962, boolean z) {
        this.f5318 = new JsonWriter(writer);
        this.f5316 = map;
        this.f5319 = map2;
        this.f5314 = c0962;
        this.f5315 = z;
    }

    @Override // defpackage.InterfaceC4148
    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final InterfaceC4148 mo4003(C0613 c0613, int i) throws IOException {
        String str = c0613.f3080;
        m4010();
        JsonWriter jsonWriter = this.f5318;
        jsonWriter.name(str);
        m4010();
        jsonWriter.value(i);
        return this;
    }

    @Override // defpackage.InterfaceC4148
    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final InterfaceC4148 mo4004(C0613 c0613, long j) throws IOException {
        String str = c0613.f3080;
        m4010();
        JsonWriter jsonWriter = this.f5318;
        jsonWriter.name(str);
        m4010();
        jsonWriter.value(j);
        return this;
    }

    @Override // defpackage.InterfaceC4148
    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final InterfaceC4148 mo4005(C0613 c0613, double d) throws IOException {
        String str = c0613.f3080;
        m4010();
        JsonWriter jsonWriter = this.f5318;
        jsonWriter.name(str);
        m4010();
        jsonWriter.value(d);
        return this;
    }

    @Override // defpackage.InterfaceC1302
    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final InterfaceC1302 mo4006(boolean z) throws IOException {
        m4010();
        this.f5318.value(z);
        return this;
    }

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final C1290 m4007(Object obj, String str) throws IOException {
        boolean z = this.f5315;
        JsonWriter jsonWriter = this.f5318;
        if (z) {
            if (obj == null) {
                return this;
            }
            m4010();
            jsonWriter.name(str);
            m4011(obj);
            return this;
        }
        m4010();
        jsonWriter.name(str);
        if (obj == null) {
            jsonWriter.nullValue();
            return this;
        }
        m4011(obj);
        return this;
    }

    @Override // defpackage.InterfaceC4148
    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final InterfaceC4148 mo4008(C0613 c0613, Object obj) throws IOException {
        m4007(obj, c0613.f3080);
        return this;
    }

    @Override // defpackage.InterfaceC1302
    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final InterfaceC1302 mo4009(String str) throws IOException {
        m4010();
        this.f5318.value(str);
        return this;
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final void m4010() {
        if (this.f5317) {
            return;
        }
        ᵹˉᵞ.ᵳٴᵶ("Parent context used since this context was created. Cannot use this context anymore.");
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final C1290 m4011(Object obj) {
        JsonWriter jsonWriter = this.f5318;
        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()) {
                    m4011(it.next());
                }
                jsonWriter.endArray();
                return this;
            }
            if (obj instanceof Map) {
                jsonWriter.beginObject();
                for (Map.Entry entry : ((Map) obj).entrySet()) {
                    Object key = entry.getKey();
                    try {
                        m4007(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;
            }
            InterfaceC3555 interfaceC3555 = (InterfaceC3555) this.f5316.get(obj.getClass());
            if (interfaceC3555 != null) {
                jsonWriter.beginObject();
                interfaceC3555.mo1298(obj, this);
                jsonWriter.endObject();
                return this;
            }
            InterfaceC2807 interfaceC2807 = (InterfaceC2807) this.f5319.get(obj.getClass());
            if (interfaceC2807 != null) {
                interfaceC2807.mo1298(obj, this);
                return this;
            }
            if (!(obj instanceof Enum)) {
                jsonWriter.beginObject();
                this.f5314.mo1298(obj, this);
                jsonWriter.endObject();
                return this;
            }
            if (obj instanceof InterfaceC1201) {
                int iMo2092 = ((InterfaceC1201) obj).mo2092();
                m4010();
                jsonWriter.value(iMo2092);
                return this;
            }
            String strName = ((Enum) obj).name();
            m4010();
            jsonWriter.value(strName);
            return this;
        }
        if (obj instanceof byte[]) {
            m4010();
            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];
                m4010();
                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) {
                m4011(numberArr[i]);
                i++;
            }
        } else {
            Object[] objArr = (Object[]) obj;
            int length6 = objArr.length;
            while (i < length6) {
                m4011(objArr[i]);
                i++;
            }
        }
        jsonWriter.endArray();
        return this;
    }

    @Override // defpackage.InterfaceC4148
    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final InterfaceC4148 mo4012(C0613 c0613, boolean z) throws IOException {
        String str = c0613.f3080;
        m4010();
        JsonWriter jsonWriter = this.f5318;
        jsonWriter.name(str);
        m4010();
        jsonWriter.value(z);
        return this;
    }
}
