package com.discord.stores; import android.content.Context; import c.d.b.a.a; import com.discord.api.premium.ClaimedOutboundPromotion; import com.discord.api.premium.OutboundPromotion; import com.discord.api.user.User; import com.discord.models.domain.ModelPayload; import com.discord.models.user.MeUser; import com.discord.stores.updates.ObservationDeck; import com.discord.stores.updates.ObservationDeckProvider; import com.discord.utilities.rest.RestAPI; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.utilities.user.UserUtils; import d0.t.n; import d0.z.d.m; import java.util.ArrayList; import java.util.List; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; /* compiled from: StoreOutboundPromotions.kt */ public final class StoreOutboundPromotions extends StoreV2 { private static final String CONSUMED_ENTITLEMENT_PROMO_ID = "CONSUMED_ENTITLEMENT_CODE"; public static final Companion Companion = new Companion(null); private static final long NO_PROMO_ID = -1; private final Dispatcher dispatcher; private final boolean isEnabled; private final ObservationDeck observationDeck; private final RestAPI restAPI; private State state; private State stateSnapshot; /* compiled from: StoreOutboundPromotions.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* compiled from: StoreOutboundPromotions.kt */ public static abstract class State { /* compiled from: StoreOutboundPromotions.kt */ public static final class Failed extends State { public static final Failed INSTANCE = new Failed(); private Failed() { super(null); } } /* compiled from: StoreOutboundPromotions.kt */ public static final class Loaded extends State { private final List validActivePromotions; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Loaded(List list) { super(null); m.checkNotNullParameter(list, "validActivePromotions"); this.validActivePromotions = list; } /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.stores.StoreOutboundPromotions$State$Loaded */ /* JADX WARN: Multi-variable type inference failed */ public static /* synthetic */ Loaded copy$default(Loaded loaded, List list, int i, Object obj) { if ((i & 1) != 0) { list = loaded.validActivePromotions; } return loaded.copy(list); } public final List component1() { return this.validActivePromotions; } public final Loaded copy(List list) { m.checkNotNullParameter(list, "validActivePromotions"); return new Loaded(list); } @Override // com.discord.stores.StoreOutboundPromotions.State public Loaded deepCopy() { return new Loaded(new ArrayList(this.validActivePromotions)); } public boolean equals(Object obj) { if (this != obj) { return (obj instanceof Loaded) && m.areEqual(this.validActivePromotions, ((Loaded) obj).validActivePromotions); } return true; } public final List getValidActivePromotions() { return this.validActivePromotions; } public int hashCode() { List list = this.validActivePromotions; if (list != null) { return list.hashCode(); } return 0; } public String toString() { return a.E(a.L("Loaded(validActivePromotions="), this.validActivePromotions, ")"); } } /* compiled from: StoreOutboundPromotions.kt */ public static final class Loading extends State { public static final Loading INSTANCE = new Loading(); private Loading() { super(null); } } private State() { } public /* synthetic */ State(DefaultConstructorMarker defaultConstructorMarker) { this(); } public State deepCopy() { return this; } } public StoreOutboundPromotions(Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI, boolean z2) { m.checkNotNullParameter(dispatcher, "dispatcher"); m.checkNotNullParameter(observationDeck, "observationDeck"); m.checkNotNullParameter(restAPI, "restAPI"); this.dispatcher = dispatcher; this.observationDeck = observationDeck; this.restAPI = restAPI; this.isEnabled = z2; State.Loading loading = State.Loading.INSTANCE; this.state = loading; this.stateSnapshot = loading; } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ StoreOutboundPromotions(Dispatcher dispatcher, ObservationDeck observationDeck, RestAPI restAPI, boolean z2, int i, DefaultConstructorMarker defaultConstructorMarker) { this(dispatcher, (i & 2) != 0 ? ObservationDeckProvider.get() : observationDeck, (i & 4) != 0 ? RestAPI.Companion.getApi() : restAPI, (i & 8) != 0 ? false : z2); } public static final /* synthetic */ Dispatcher access$getDispatcher$p(StoreOutboundPromotions storeOutboundPromotions) { return storeOutboundPromotions.dispatcher; } public static final /* synthetic */ RestAPI access$getRestAPI$p(StoreOutboundPromotions storeOutboundPromotions) { return storeOutboundPromotions.restAPI; } public static final /* synthetic */ State access$getState$p(StoreOutboundPromotions storeOutboundPromotions) { return storeOutboundPromotions.state; } public static final /* synthetic */ void access$setState$p(StoreOutboundPromotions storeOutboundPromotions, State state) { storeOutboundPromotions.state = state; } public final Observable claimOutboundPromotion(long j) { return this.restAPI.claimOutboundPromotion(j); } public final Observable> fetchClaimedOutboundPromotions() { return this.restAPI.getClaimedOutboundPromotions(); } public final State getState() { return this.stateSnapshot; } @StoreThread public final void handleConnectionOpen$app_productionBetaRelease(ModelPayload modelPayload) { m.checkNotNullParameter(modelPayload, "readyPayload"); if (this.isEnabled) { UserUtils userUtils = UserUtils.INSTANCE; User me2 = modelPayload.getMe(); m.checkNotNullExpressionValue(me2, "readyPayload.me"); if (userUtils.isPremium(new MeUser(me2))) { this.state = State.Loading.INSTANCE; markChanged(); Observable z2 = ObservableExtensionsKt.restSubscribeOn$default(this.restAPI.getAllActiveOutboundPromotions(), false, 1, null).z(new StoreOutboundPromotions$handleConnectionOpen$1(this)); m.checkNotNullExpressionValue(z2, "restAPI\n .getAl… }\n }"); ObservableExtensionsKt.appSubscribe$default(z2, StoreOutboundPromotions.class, (Context) null, (Function1) null, new StoreOutboundPromotions$handleConnectionOpen$2(this), (Function0) null, (Function0) null, new StoreOutboundPromotions$handleConnectionOpen$3(this), 54, (Object) null); return; } } this.state = new State.Loaded(n.emptyList()); markChanged(); } public final Observable observeState() { Observable r = ObservationDeck.connectRx$default(this.observationDeck, new ObservationDeck.UpdateSource[]{this}, false, null, null, new StoreOutboundPromotions$observeState$1(this), 14, null).r(); m.checkNotNullExpressionValue(r, "observationDeck.connectR… .distinctUntilChanged()"); return r; } @Override // com.discord.stores.StoreV2 public void snapshotData() { super.snapshotData(); this.stateSnapshot = this.state.deepCopy(); } }