package com.revenuecat.purchases.subscriberattributes;

import J4.c;
import R4.n;
import java.util.Iterator;
import java.util.Map;
import kotlin.jvm.internal.o;
import kotlin.jvm.internal.p;
import org.json.JSONException;
import org.json.JSONObject;
import w4.k;
import x4.AbstractC3229F;

/* JADX INFO: loaded from: classes3.dex */
public final class SubscriberAttributesFactoriesKt {

    /* JADX INFO: renamed from: com.revenuecat.purchases.subscriberattributes.SubscriberAttributesFactoriesKt$buildSubscriberAttributesMap$1, reason: invalid class name */
    public static final class AnonymousClass1 extends p implements c {
        final /* synthetic */ JSONObject $this_buildSubscriberAttributesMap;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public AnonymousClass1(JSONObject jSONObject) {
            super(1);
            this.$this_buildSubscriberAttributesMap = jSONObject;
        }

        @Override // J4.c
        public final k invoke(String str) throws JSONException {
            Object obj = this.$this_buildSubscriberAttributesMap.get(str);
            o.f(obj, "null cannot be cast to non-null type org.json.JSONObject");
            return new k(str, new SubscriberAttribute((JSONObject) obj));
        }
    }

    /* JADX INFO: renamed from: com.revenuecat.purchases.subscriberattributes.SubscriberAttributesFactoriesKt$buildSubscriberAttributesMapPerUser$1, reason: invalid class name and case insensitive filesystem */
    public static final class C14431 extends p implements c {
        final /* synthetic */ JSONObject $attributesJSONObject;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C14431(JSONObject jSONObject) {
            super(1);
            this.$attributesJSONObject = jSONObject;
        }

        @Override // J4.c
        public final k invoke(String str) throws JSONException {
            Object obj = this.$attributesJSONObject.get(str);
            o.f(obj, "null cannot be cast to non-null type org.json.JSONObject");
            return new k(str, SubscriberAttributesFactoriesKt.buildSubscriberAttributesMap((JSONObject) obj));
        }
    }

    public static final Map<String, SubscriberAttribute> buildLegacySubscriberAttributes(JSONObject jSONObject) throws JSONException {
        o.h(jSONObject, "<this>");
        JSONObject attributesJSONObject = jSONObject.getJSONObject("attributes");
        o.g(attributesJSONObject, "attributesJSONObject");
        return buildSubscriberAttributesMap(attributesJSONObject);
    }

    public static final Map<String, SubscriberAttribute> buildSubscriberAttributesMap(JSONObject jSONObject) {
        o.h(jSONObject, "<this>");
        Iterator<String> itKeys = jSONObject.keys();
        o.g(itKeys, "this.keys()");
        return AbstractC3229F.E(n.b0(n.X(itKeys), new AnonymousClass1(jSONObject)));
    }

    public static final Map<String, Map<String, SubscriberAttribute>> buildSubscriberAttributesMapPerUser(JSONObject jSONObject) throws JSONException {
        o.h(jSONObject, "<this>");
        JSONObject jSONObject2 = jSONObject.getJSONObject("attributes");
        Iterator<String> itKeys = jSONObject2.keys();
        o.g(itKeys, "attributesJSONObject.keys()");
        return AbstractC3229F.E(n.b0(n.X(itKeys), new C14431(jSONObject2)));
    }
}
