package i4;

import androidx.datastore.preferences.protobuf.w;
import f4.k;
import h4.f;
import h4.h;
import i4.d;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
import rm.n0;
import rm.t;
import sm.c0;

/* loaded from: classes.dex */
public final class h implements k {

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

    /* renamed from: b, reason: collision with root package name */
    private static final String f22419b = "preferences_pb";

    /* loaded from: classes.dex */
    public /* synthetic */ class a {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f22420a;

        static {
            int[] iArr = new int[h.b.values().length];
            iArr[h.b.BOOLEAN.ordinal()] = 1;
            iArr[h.b.FLOAT.ordinal()] = 2;
            iArr[h.b.DOUBLE.ordinal()] = 3;
            iArr[h.b.INTEGER.ordinal()] = 4;
            iArr[h.b.LONG.ordinal()] = 5;
            iArr[h.b.STRING.ordinal()] = 6;
            iArr[h.b.STRING_SET.ordinal()] = 7;
            iArr[h.b.VALUE_NOT_SET.ordinal()] = 8;
            f22420a = iArr;
        }
    }

    private h() {
    }

    private final void d(String str, h4.h hVar, i4.a aVar) {
        Set X0;
        h.b S = hVar.S();
        switch (S == null ? -1 : a.f22420a[S.ordinal()]) {
            case -1:
                throw new f4.a("Value case is null.", null, 2, null);
            case 0:
            default:
                throw new t();
            case 1:
                aVar.j(f.a(str), Boolean.valueOf(hVar.K()));
                return;
            case 2:
                aVar.j(f.c(str), Float.valueOf(hVar.N()));
                return;
            case 3:
                aVar.j(f.b(str), Double.valueOf(hVar.M()));
                return;
            case 4:
                aVar.j(f.d(str), Integer.valueOf(hVar.O()));
                return;
            case 5:
                aVar.j(f.e(str), Long.valueOf(hVar.P()));
                return;
            case 6:
                d.a f10 = f.f(str);
                String Q = hVar.Q();
                kotlin.jvm.internal.t.f(Q, "value.string");
                aVar.j(f10, Q);
                return;
            case 7:
                d.a g10 = f.g(str);
                List H = hVar.R().H();
                kotlin.jvm.internal.t.f(H, "value.stringSet.stringsList");
                X0 = c0.X0(H);
                aVar.j(g10, X0);
                return;
            case 8:
                throw new f4.a("Value not set.", null, 2, null);
        }
    }

    private final h4.h g(Object obj) {
        if (obj instanceof Boolean) {
            w i10 = h4.h.T().s(((Boolean) obj).booleanValue()).i();
            kotlin.jvm.internal.t.f(i10, "newBuilder().setBoolean(value).build()");
            return (h4.h) i10;
        }
        if (obj instanceof Float) {
            w i11 = h4.h.T().u(((Number) obj).floatValue()).i();
            kotlin.jvm.internal.t.f(i11, "newBuilder().setFloat(value).build()");
            return (h4.h) i11;
        }
        if (obj instanceof Double) {
            w i12 = h4.h.T().t(((Number) obj).doubleValue()).i();
            kotlin.jvm.internal.t.f(i12, "newBuilder().setDouble(value).build()");
            return (h4.h) i12;
        }
        if (obj instanceof Integer) {
            w i13 = h4.h.T().v(((Number) obj).intValue()).i();
            kotlin.jvm.internal.t.f(i13, "newBuilder().setInteger(value).build()");
            return (h4.h) i13;
        }
        if (obj instanceof Long) {
            w i14 = h4.h.T().w(((Number) obj).longValue()).i();
            kotlin.jvm.internal.t.f(i14, "newBuilder().setLong(value).build()");
            return (h4.h) i14;
        }
        if (obj instanceof String) {
            w i15 = h4.h.T().x((String) obj).i();
            kotlin.jvm.internal.t.f(i15, "newBuilder().setString(value).build()");
            return (h4.h) i15;
        }
        if (!(obj instanceof Set)) {
            throw new IllegalStateException(kotlin.jvm.internal.t.p("PreferencesSerializer does not support type: ", obj.getClass().getName()));
        }
        w i16 = h4.h.T().y(h4.g.I().s((Set) obj)).i();
        kotlin.jvm.internal.t.f(i16, "newBuilder().setStringSet(\n                    StringSet.newBuilder().addAllStrings(value as Set<String>)\n                ).build()");
        return (h4.h) i16;
    }

    @Override // f4.k
    public Object c(InputStream inputStream, vm.d dVar) {
        h4.f a10 = h4.d.f20825a.a(inputStream);
        i4.a b10 = e.b(new d.b[0]);
        Map F = a10.F();
        kotlin.jvm.internal.t.f(F, "preferencesProto.preferencesMap");
        for (Map.Entry entry : F.entrySet()) {
            String name = (String) entry.getKey();
            h4.h value = (h4.h) entry.getValue();
            h hVar = f22418a;
            kotlin.jvm.internal.t.f(name, "name");
            kotlin.jvm.internal.t.f(value, "value");
            hVar.d(name, value, b10);
        }
        return b10.d();
    }

    @Override // f4.k
    /* renamed from: e, reason: merged with bridge method [inline-methods] */
    public d a() {
        return e.a();
    }

    public final String f() {
        return f22419b;
    }

    @Override // f4.k
    /* renamed from: h, reason: merged with bridge method [inline-methods] */
    public Object b(d dVar, OutputStream outputStream, vm.d dVar2) {
        Map a10 = dVar.a();
        f.a I = h4.f.I();
        for (Map.Entry entry : a10.entrySet()) {
            I.s(((d.a) entry.getKey()).a(), g(entry.getValue()));
        }
        ((h4.f) I.i()).g(outputStream);
        return n0.f34904a;
    }
}
