package com.google.firebase.remoteconfig.internal; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes3.dex */ public class ConfigContainer { public static final Date DEFAULTS_FETCH_TIME = new Date(0); public JSONArray abtExperiments; public JSONObject configsJson; public JSONObject containerJson; public Date fetchTime; public JSONObject personalizationMetadata; public JSONArray rolloutMetadata; public long templateVersionNumber; public JSONArray getAbtExperiments() { return this.abtExperiments; } public JSONObject getConfigs() { return this.configsJson; } public Date getFetchTime() { return this.fetchTime; } public JSONObject getPersonalizationMetadata() { return this.personalizationMetadata; } public JSONArray getRolloutMetadata() { return this.rolloutMetadata; } public long getTemplateVersionNumber() { return this.templateVersionNumber; } public ConfigContainer(JSONObject jSONObject, Date date, JSONArray jSONArray, JSONObject jSONObject2, long j, JSONArray jSONArray2) { JSONObject jSONObject3 = new JSONObject(); jSONObject3.put("configs_key", jSONObject); jSONObject3.put("fetch_time_key", date.getTime()); jSONObject3.put("abt_experiments_key", jSONArray); jSONObject3.put("personalization_metadata_key", jSONObject2); jSONObject3.put("template_version_number_key", j); jSONObject3.put("rollout_metadata_key", jSONArray2); this.configsJson = jSONObject; this.fetchTime = date; this.abtExperiments = jSONArray; this.personalizationMetadata = jSONObject2; this.templateVersionNumber = j; this.rolloutMetadata = jSONArray2; this.containerJson = jSONObject3; } public static ConfigContainer copyOf(JSONObject jSONObject) { JSONObject optJSONObject = jSONObject.optJSONObject("personalization_metadata_key"); if (optJSONObject == null) { optJSONObject = new JSONObject(); } JSONObject jSONObject2 = optJSONObject; JSONArray optJSONArray = jSONObject.optJSONArray("rollout_metadata_key"); if (optJSONArray == null) { optJSONArray = new JSONArray(); } return new ConfigContainer(jSONObject.getJSONObject("configs_key"), new Date(jSONObject.getLong("fetch_time_key")), jSONObject.getJSONArray("abt_experiments_key"), jSONObject2, jSONObject.optLong("template_version_number_key"), optJSONArray); } public static ConfigContainer deepCopyOf(JSONObject jSONObject) { return copyOf(new JSONObject(jSONObject.toString())); } public String toString() { return this.containerJson.toString(); } public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof ConfigContainer) { return this.containerJson.toString().equals(((ConfigContainer) obj).toString()); } return false; } public final Map createRolloutParameterKeyMap() { HashMap hashMap = new HashMap(); for (int i = 0; i < getRolloutMetadata().length(); i++) { JSONObject jSONObject = getRolloutMetadata().getJSONObject(i); String string = jSONObject.getString("rolloutId"); String string2 = jSONObject.getString("variantId"); JSONArray jSONArray = jSONObject.getJSONArray("affectedParameterKeys"); for (int i2 = 0; i2 < jSONArray.length(); i2++) { String string3 = jSONArray.getString(i2); if (!hashMap.containsKey(string3)) { hashMap.put(string3, new HashMap()); } Map map = (Map) hashMap.get(string3); if (map != null) { map.put(string, string2); } } } return hashMap; } public Set getChangedParams(ConfigContainer configContainer) { JSONObject configs = deepCopyOf(configContainer.containerJson).getConfigs(); Map createRolloutParameterKeyMap = createRolloutParameterKeyMap(); Map createRolloutParameterKeyMap2 = configContainer.createRolloutParameterKeyMap(); HashSet hashSet = new HashSet(); Iterator keys = getConfigs().keys(); while (keys.hasNext()) { String next = keys.next(); if (!configContainer.getConfigs().has(next)) { hashSet.add(next); } else if (!getConfigs().get(next).equals(configContainer.getConfigs().get(next))) { hashSet.add(next); } else if ((getPersonalizationMetadata().has(next) && !configContainer.getPersonalizationMetadata().has(next)) || (!getPersonalizationMetadata().has(next) && configContainer.getPersonalizationMetadata().has(next))) { hashSet.add(next); } else if (getPersonalizationMetadata().has(next) && configContainer.getPersonalizationMetadata().has(next) && !getPersonalizationMetadata().getJSONObject(next).toString().equals(configContainer.getPersonalizationMetadata().getJSONObject(next).toString())) { hashSet.add(next); } else if (createRolloutParameterKeyMap.containsKey(next) != createRolloutParameterKeyMap2.containsKey(next)) { hashSet.add(next); } else if (createRolloutParameterKeyMap.containsKey(next) && createRolloutParameterKeyMap2.containsKey(next) && !((Map) createRolloutParameterKeyMap.get(next)).equals(createRolloutParameterKeyMap2.get(next))) { hashSet.add(next); } else { configs.remove(next); } } Iterator keys2 = configs.keys(); while (keys2.hasNext()) { hashSet.add(keys2.next()); } return hashSet; } public int hashCode() { return this.containerJson.hashCode(); } public static class Builder { public JSONArray builderAbtExperiments; public JSONObject builderConfigsJson; public Date builderFetchTime; public JSONObject builderPersonalizationMetadata; public JSONArray builderRolloutMetadata; public long builderTemplateVersionNumber; public Builder withFetchTime(Date date) { this.builderFetchTime = date; return this; } public Builder withTemplateVersionNumber(long j) { this.builderTemplateVersionNumber = j; return this; } public Builder() { this.builderConfigsJson = new JSONObject(); this.builderFetchTime = ConfigContainer.DEFAULTS_FETCH_TIME; this.builderAbtExperiments = new JSONArray(); this.builderPersonalizationMetadata = new JSONObject(); this.builderTemplateVersionNumber = 0L; this.builderRolloutMetadata = new JSONArray(); } public Builder replaceConfigsWith(JSONObject jSONObject) { try { this.builderConfigsJson = new JSONObject(jSONObject.toString()); } catch (JSONException unused) { } return this; } public Builder withAbtExperiments(JSONArray jSONArray) { try { this.builderAbtExperiments = new JSONArray(jSONArray.toString()); } catch (JSONException unused) { } return this; } public Builder withPersonalizationMetadata(JSONObject jSONObject) { try { this.builderPersonalizationMetadata = new JSONObject(jSONObject.toString()); } catch (JSONException unused) { } return this; } public Builder withRolloutMetadata(JSONArray jSONArray) { try { this.builderRolloutMetadata = new JSONArray(jSONArray.toString()); } catch (JSONException unused) { } return this; } public ConfigContainer build() { return new ConfigContainer(this.builderConfigsJson, this.builderFetchTime, this.builderAbtExperiments, this.builderPersonalizationMetadata, this.builderTemplateVersionNumber, this.builderRolloutMetadata); } } public static Builder newBuilder() { return new Builder(); } }