package com.adobe.marketing.mobile.userprofile;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import wg.i0;
import wg.t;
import wg.v;

/* loaded from: classes4.dex */
class c {

    /* renamed from: a, reason: collision with root package name */
    private final v f12411a;

    /* renamed from: b, reason: collision with root package name */
    private Map f12412b = new HashMap();

    /* JADX INFO: Access modifiers changed from: package-private */
    public c() {
        v a10 = i0.f().d().a("ADBUserProfile");
        this.f12411a = a10;
        if (a10 == null) {
            throw new b("Failed to create a NamedCollection service with the collection name [ADBUserProfile]");
        }
    }

    private void g(String str, Object obj) {
        if (obj == null) {
            this.f12412b.remove(str);
        } else {
            this.f12412b.put(str, obj);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(List list) {
        Iterator it = list.iterator();
        while (it.hasNext()) {
            this.f12412b.remove((String) it.next());
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Object b(String str) {
        return this.f12412b.get(str);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Map c() {
        return Collections.unmodifiableMap(this.f12412b);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Map d(String str) {
        try {
            return ch.b.f(Object.class, this.f12412b, str);
        } catch (ch.c unused) {
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean e() {
        String string = this.f12411a.getString("user_profile", "{}");
        if (string == null) {
            return true;
        }
        try {
            this.f12412b = a.a(new JSONObject(string));
            return true;
        } catch (JSONException e10) {
            t.b("UserProfile", "PersistentProfileData", "Could not load persistent profile data: %s", e10);
            return false;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean f() {
        try {
            if (this.f12411a == null) {
                return false;
            }
            String jSONObject = new JSONObject(this.f12412b).toString();
            this.f12411a.e("user_profile", jSONObject);
            t.e("UserProfile", "PersistentProfileData", "Profile Data is persisted : %s", jSONObject);
            return true;
        } catch (Exception e10) {
            t.b("UserProfile", "PersistentProfileData", "Profile Data is not persisted : %s", e10);
            return false;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void h(Map map) {
        for (Map.Entry entry : map.entrySet()) {
            g((String) entry.getKey(), entry.getValue());
        }
    }
}
