package com.discord.widgets.chat.input; import c.d.b.a.a; import com.discord.models.commands.Application; import com.discord.models.commands.ApplicationCommand; import com.discord.models.commands.ModelApplicationComparator; import com.discord.stores.DiscoverCommands; import com.discord.widgets.chat.input.autocomplete.ApplicationCommandAutocompletable; import com.discord.widgets.chat.input.autocomplete.ApplicationCommandLoadingPlaceholder; import com.discord.widgets.chat.input.autocomplete.ApplicationPlaceholder; import com.discord.widgets.chat.input.autocomplete.Autocompletable; import d0.t.u; import d0.z.d.m; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.TreeSet; import kotlin.Pair; import kotlin.jvm.internal.DefaultConstructorMarker; /* compiled from: WidgetChatInputDiscoveryCommandsModel.kt */ public final class WidgetChatInputDiscoveryCommandsModel { public static final Companion Companion = new Companion(null); private final List>> commandsByApplication; private final boolean hasMoreAfter; private final boolean hasMoreBefore; private final Long jumpedApplicationId; private final int jumpedSequenceId; /* compiled from: WidgetChatInputDiscoveryCommandsModel.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } private final List createPlaceholderModels(int i, boolean z2, Application application) { ArrayList arrayList = new ArrayList(); for (int i2 = 0; i2 < i; i2++) { arrayList.add(i2, new ApplicationCommandLoadingPlaceholder(application)); } return arrayList; } private final String getPlaceholderTag(boolean z2, long j, int i) { return "placeholder-" + z2 + '-' + j + '-' + i; } public final WidgetChatInputDiscoveryCommandsModel parseModelDiscoveryCommands(List list, DiscoverCommands discoverCommands, boolean z2, int i) { m.checkNotNullParameter(list, "applications"); m.checkNotNullParameter(discoverCommands, "discoveryCommands"); HashMap hashMap = new HashMap(); for (Application application : list) { hashMap.put(Long.valueOf(application.getId()), application); } TreeSet treeSet = new TreeSet(ModelApplicationComparator.Companion); HashMap hashMap2 = new HashMap(); for (ApplicationCommand applicationCommand : discoverCommands.getCommands()) { long applicationId = applicationCommand.getApplicationId(); Application application2 = (Application) hashMap.get(Long.valueOf(applicationId)); if (application2 != null) { m.checkNotNullExpressionValue(application2, "appMap[appId] ?: continue"); treeSet.add(application2); ApplicationCommandAutocompletable applicationCommandAutocompletable = new ApplicationCommandAutocompletable(application2, applicationCommand); if (!hashMap2.containsKey(Long.valueOf(applicationId))) { ArrayList arrayList = new ArrayList(); arrayList.add(applicationCommandAutocompletable); hashMap2.put(Long.valueOf(applicationId), arrayList); } else { List list2 = (List) hashMap2.get(Long.valueOf(applicationId)); if (list2 != null) { list2.add(applicationCommandAutocompletable); } } } } ArrayList arrayList2 = new ArrayList(); for (Application application3 : treeSet) { List list3 = (List) hashMap2.get(Long.valueOf(application3.getId())); if (list3 != null && (true ^ list3.isEmpty())) { if (z2) { list3.add(0, new ApplicationPlaceholder(application3)); } arrayList2.add(new Pair(application3, list3)); } } if (i > 0 && (!arrayList2.isEmpty())) { if (discoverCommands.getHasMoreBefore()) { Pair pair = (Pair) u.first((List) arrayList2); Application application4 = (Application) pair.component1(); arrayList2.set(0, new Pair(application4, u.plus((Collection) createPlaceholderModels(i, true, application4), (Iterable) ((List) pair.component2())))); } if (discoverCommands.getHasMoreAfter()) { Pair pair2 = (Pair) u.last((List) arrayList2); Application application5 = (Application) pair2.component1(); arrayList2.set(arrayList2.size() - 1, new Pair(application5, u.plus((Collection) ((List) pair2.component2()), (Iterable) createPlaceholderModels(i, false, application5)))); } } return new WidgetChatInputDiscoveryCommandsModel(arrayList2, discoverCommands.getHasMoreBefore(), discoverCommands.getHasMoreAfter(), discoverCommands.getJumpedSequenceId(), discoverCommands.getJumpedApplicationId()); } } /* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: java.util.List>> */ /* JADX WARN: Multi-variable type inference failed */ public WidgetChatInputDiscoveryCommandsModel(List>> list, boolean z2, boolean z3, int i, Long l) { m.checkNotNullParameter(list, "commandsByApplication"); this.commandsByApplication = list; this.hasMoreBefore = z2; this.hasMoreAfter = z3; this.jumpedSequenceId = i; this.jumpedApplicationId = l; } /* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: com.discord.widgets.chat.input.WidgetChatInputDiscoveryCommandsModel */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ WidgetChatInputDiscoveryCommandsModel copy$default(WidgetChatInputDiscoveryCommandsModel widgetChatInputDiscoveryCommandsModel, List list, boolean z2, boolean z3, int i, Long l, int i2, Object obj) { if ((i2 & 1) != 0) { list = widgetChatInputDiscoveryCommandsModel.commandsByApplication; } if ((i2 & 2) != 0) { z2 = widgetChatInputDiscoveryCommandsModel.hasMoreBefore; } if ((i2 & 4) != 0) { z3 = widgetChatInputDiscoveryCommandsModel.hasMoreAfter; } if ((i2 & 8) != 0) { i = widgetChatInputDiscoveryCommandsModel.jumpedSequenceId; } if ((i2 & 16) != 0) { l = widgetChatInputDiscoveryCommandsModel.jumpedApplicationId; } return widgetChatInputDiscoveryCommandsModel.copy(list, z2, z3, i, l); } public static final WidgetChatInputDiscoveryCommandsModel parseModelDiscoveryCommands(List list, DiscoverCommands discoverCommands, boolean z2, int i) { return Companion.parseModelDiscoveryCommands(list, discoverCommands, z2, i); } public final List>> component1() { return this.commandsByApplication; } public final boolean component2() { return this.hasMoreBefore; } public final boolean component3() { return this.hasMoreAfter; } public final int component4() { return this.jumpedSequenceId; } public final Long component5() { return this.jumpedApplicationId; } public final WidgetChatInputDiscoveryCommandsModel copy(List>> list, boolean z2, boolean z3, int i, Long l) { m.checkNotNullParameter(list, "commandsByApplication"); return new WidgetChatInputDiscoveryCommandsModel(list, z2, z3, i, l); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof WidgetChatInputDiscoveryCommandsModel)) { return false; } WidgetChatInputDiscoveryCommandsModel widgetChatInputDiscoveryCommandsModel = (WidgetChatInputDiscoveryCommandsModel) obj; return m.areEqual(this.commandsByApplication, widgetChatInputDiscoveryCommandsModel.commandsByApplication) && this.hasMoreBefore == widgetChatInputDiscoveryCommandsModel.hasMoreBefore && this.hasMoreAfter == widgetChatInputDiscoveryCommandsModel.hasMoreAfter && this.jumpedSequenceId == widgetChatInputDiscoveryCommandsModel.jumpedSequenceId && m.areEqual(this.jumpedApplicationId, widgetChatInputDiscoveryCommandsModel.jumpedApplicationId); } public final List>> getCommandsByApplication() { return this.commandsByApplication; } public final List getFlattenCommandsModel() { ArrayList arrayList = new ArrayList(); for (Pair> pair : this.commandsByApplication) { arrayList.addAll(pair.component2()); } return arrayList; } public final boolean getHasMoreAfter() { return this.hasMoreAfter; } public final boolean getHasMoreBefore() { return this.hasMoreBefore; } public final Long getJumpedApplicationId() { return this.jumpedApplicationId; } public final int getJumpedSequenceId() { return this.jumpedSequenceId; } public int hashCode() { List>> list = this.commandsByApplication; int i = 0; int hashCode = (list != null ? list.hashCode() : 0) * 31; boolean z2 = this.hasMoreBefore; int i2 = 1; if (z2) { z2 = true; } int i3 = z2 ? 1 : 0; int i4 = z2 ? 1 : 0; int i5 = z2 ? 1 : 0; int i6 = (hashCode + i3) * 31; boolean z3 = this.hasMoreAfter; if (!z3) { i2 = z3 ? 1 : 0; } int i7 = (((i6 + i2) * 31) + this.jumpedSequenceId) * 31; Long l = this.jumpedApplicationId; if (l != null) { i = l.hashCode(); } return i7 + i; } public String toString() { StringBuilder L = a.L("WidgetChatInputDiscoveryCommandsModel(commandsByApplication="); L.append(this.commandsByApplication); L.append(", hasMoreBefore="); L.append(this.hasMoreBefore); L.append(", hasMoreAfter="); L.append(this.hasMoreAfter); L.append(", jumpedSequenceId="); L.append(this.jumpedSequenceId); L.append(", jumpedApplicationId="); return a.C(L, this.jumpedApplicationId, ")"); } }