package com.discord.stores; import android.content.Context; import c.d.b.a.a; import com.discord.models.domain.ModelGift; import com.discord.restapi.RestAPIParams; import com.discord.utilities.error.Error; import com.discord.utilities.rest.RestAPI; import com.discord.utilities.rx.ObservableExtensionsKt; import com.discord.widgets.chat.input.MentionUtilsKt; import d0.t.h0; import d0.z.d.m; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import rx.Observable; import rx.subjects.BehaviorSubject; /* compiled from: StoreGifting.kt */ public final class StoreGifting { public static final Companion Companion = new Companion(null); private final Dispatcher dispatcher; private HashMap knownGifts = new HashMap<>(); private final BehaviorSubject> knownGiftsSubject = BehaviorSubject.l0(h0.emptyMap()); /* compiled from: StoreGifting.kt */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } /* JADX DEBUG: TODO: convert one arg to string using `String.valueOf()`, args: [(r2v0 long), (wrap: char : ?: SGET com.discord.widgets.chat.input.MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR char), (r4v0 java.lang.Long)] */ public final String makeComboId(long j, Long l) { StringBuilder sb = new StringBuilder(); sb.append(j); sb.append(MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR); sb.append(l); return sb.toString(); } } /* compiled from: StoreGifting.kt */ public static abstract class GiftState { /* compiled from: StoreGifting.kt */ public static final class Invalid extends GiftState { public static final Invalid INSTANCE = new Invalid(); private Invalid() { super(null); } } /* compiled from: StoreGifting.kt */ public static final class LoadFailed extends GiftState { public static final LoadFailed INSTANCE = new LoadFailed(); private LoadFailed() { super(null); } } /* compiled from: StoreGifting.kt */ public static final class Loading extends GiftState { public static final Loading INSTANCE = new Loading(); private Loading() { super(null); } } /* compiled from: StoreGifting.kt */ public static final class RedeemedFailed extends GiftState implements HasGift { private final boolean canRetry; private final Integer errorCode; private final ModelGift gift; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public RedeemedFailed(ModelGift modelGift, boolean z2, Integer num) { super(null); m.checkNotNullParameter(modelGift, "gift"); this.gift = modelGift; this.canRetry = z2; this.errorCode = num; } public static /* synthetic */ RedeemedFailed copy$default(RedeemedFailed redeemedFailed, ModelGift modelGift, boolean z2, Integer num, int i, Object obj) { if ((i & 1) != 0) { modelGift = redeemedFailed.getGift(); } if ((i & 2) != 0) { z2 = redeemedFailed.canRetry; } if ((i & 4) != 0) { num = redeemedFailed.errorCode; } return redeemedFailed.copy(modelGift, z2, num); } public final ModelGift component1() { return getGift(); } public final boolean component2() { return this.canRetry; } public final Integer component3() { return this.errorCode; } public final RedeemedFailed copy(ModelGift modelGift, boolean z2, Integer num) { m.checkNotNullParameter(modelGift, "gift"); return new RedeemedFailed(modelGift, z2, num); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof RedeemedFailed)) { return false; } RedeemedFailed redeemedFailed = (RedeemedFailed) obj; return m.areEqual(getGift(), redeemedFailed.getGift()) && this.canRetry == redeemedFailed.canRetry && m.areEqual(this.errorCode, redeemedFailed.errorCode); } public final boolean getCanRetry() { return this.canRetry; } public final Integer getErrorCode() { return this.errorCode; } @Override // com.discord.stores.StoreGifting.HasGift public ModelGift getGift() { return this.gift; } public int hashCode() { ModelGift gift = getGift(); int i = 0; int hashCode = (gift != null ? gift.hashCode() : 0) * 31; boolean z2 = this.canRetry; if (z2) { z2 = true; } int i2 = z2 ? 1 : 0; int i3 = z2 ? 1 : 0; int i4 = z2 ? 1 : 0; int i5 = (hashCode + i2) * 31; Integer num = this.errorCode; if (num != null) { i = num.hashCode(); } return i5 + i; } public String toString() { StringBuilder R = a.R("RedeemedFailed(gift="); R.append(getGift()); R.append(", canRetry="); R.append(this.canRetry); R.append(", errorCode="); return a.E(R, this.errorCode, ")"); } } /* compiled from: StoreGifting.kt */ public static final class Redeeming extends GiftState implements HasGift { private final ModelGift gift; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Redeeming(ModelGift modelGift) { super(null); m.checkNotNullParameter(modelGift, "gift"); this.gift = modelGift; } public static /* synthetic */ Redeeming copy$default(Redeeming redeeming, ModelGift modelGift, int i, Object obj) { if ((i & 1) != 0) { modelGift = redeeming.getGift(); } return redeeming.copy(modelGift); } public final ModelGift component1() { return getGift(); } public final Redeeming copy(ModelGift modelGift) { m.checkNotNullParameter(modelGift, "gift"); return new Redeeming(modelGift); } public boolean equals(Object obj) { if (this != obj) { return (obj instanceof Redeeming) && m.areEqual(getGift(), ((Redeeming) obj).getGift()); } return true; } @Override // com.discord.stores.StoreGifting.HasGift public ModelGift getGift() { return this.gift; } public int hashCode() { ModelGift gift = getGift(); if (gift != null) { return gift.hashCode(); } return 0; } public String toString() { StringBuilder R = a.R("Redeeming(gift="); R.append(getGift()); R.append(")"); return R.toString(); } } /* compiled from: StoreGifting.kt */ public static final class Resolved extends GiftState implements HasGift { private final ModelGift gift; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Resolved(ModelGift modelGift) { super(null); m.checkNotNullParameter(modelGift, "gift"); this.gift = modelGift; } public static /* synthetic */ Resolved copy$default(Resolved resolved, ModelGift modelGift, int i, Object obj) { if ((i & 1) != 0) { modelGift = resolved.getGift(); } return resolved.copy(modelGift); } public final ModelGift component1() { return getGift(); } public final Resolved copy(ModelGift modelGift) { m.checkNotNullParameter(modelGift, "gift"); return new Resolved(modelGift); } public boolean equals(Object obj) { if (this != obj) { return (obj instanceof Resolved) && m.areEqual(getGift(), ((Resolved) obj).getGift()); } return true; } @Override // com.discord.stores.StoreGifting.HasGift public ModelGift getGift() { return this.gift; } public int hashCode() { ModelGift gift = getGift(); if (gift != null) { return gift.hashCode(); } return 0; } public String toString() { StringBuilder R = a.R("Resolved(gift="); R.append(getGift()); R.append(")"); return R.toString(); } } /* compiled from: StoreGifting.kt */ public static final class Revoking extends GiftState implements HasGift { private final ModelGift gift; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public Revoking(ModelGift modelGift) { super(null); m.checkNotNullParameter(modelGift, "gift"); this.gift = modelGift; } public static /* synthetic */ Revoking copy$default(Revoking revoking, ModelGift modelGift, int i, Object obj) { if ((i & 1) != 0) { modelGift = revoking.getGift(); } return revoking.copy(modelGift); } public final ModelGift component1() { return getGift(); } public final Revoking copy(ModelGift modelGift) { m.checkNotNullParameter(modelGift, "gift"); return new Revoking(modelGift); } public boolean equals(Object obj) { if (this != obj) { return (obj instanceof Revoking) && m.areEqual(getGift(), ((Revoking) obj).getGift()); } return true; } @Override // com.discord.stores.StoreGifting.HasGift public ModelGift getGift() { return this.gift; } public int hashCode() { ModelGift gift = getGift(); if (gift != null) { return gift.hashCode(); } return 0; } public String toString() { StringBuilder R = a.R("Revoking(gift="); R.append(getGift()); R.append(")"); return R.toString(); } } private GiftState() { } public /* synthetic */ GiftState(DefaultConstructorMarker defaultConstructorMarker) { this(); } } /* compiled from: StoreGifting.kt */ public interface HasGift { ModelGift getGift(); } public final /* synthetic */ class WhenMappings { public static final /* synthetic */ int[] $EnumSwitchMapping$0; public static final /* synthetic */ int[] $EnumSwitchMapping$1; public static final /* synthetic */ int[] $EnumSwitchMapping$2; static { Error.Type.values(); int[] iArr = new int[17]; $EnumSwitchMapping$0 = iArr; Error.Type type = Error.Type.DISCORD_REQUEST_ERROR; iArr[type.ordinal()] = 1; Error.Type type2 = Error.Type.NETWORK; iArr[type2.ordinal()] = 2; Error.Type.values(); int[] iArr2 = new int[17]; $EnumSwitchMapping$1 = iArr2; iArr2[type.ordinal()] = 1; iArr2[type2.ordinal()] = 2; Error.Type.values(); int[] iArr3 = new int[17]; $EnumSwitchMapping$2 = iArr3; iArr3[type.ordinal()] = 1; iArr3[type2.ordinal()] = 2; } } public StoreGifting(Dispatcher dispatcher) { m.checkNotNullParameter(dispatcher, "dispatcher"); this.dispatcher = dispatcher; } public static final /* synthetic */ void access$clearGiftsForSku(StoreGifting storeGifting, long j, Long l) { storeGifting.clearGiftsForSku(j, l); } public static final /* synthetic */ void access$fetchGift(StoreGifting storeGifting, String str) { storeGifting.fetchGift(str); } public static final /* synthetic */ void access$removeGiftCode(StoreGifting storeGifting, String str) { storeGifting.removeGiftCode(str); } public static final /* synthetic */ void access$setGifts(StoreGifting storeGifting, String str, GiftState giftState) { storeGifting.setGifts(str, giftState); } @StoreThread private final void clearGiftsForSku(long j, Long l) { HashMap hashMap = this.knownGifts; LinkedHashMap linkedHashMap = new LinkedHashMap(); for (Map.Entry entry : hashMap.entrySet()) { GiftState value = entry.getValue(); boolean z2 = true; if (value instanceof GiftState.Resolved) { GiftState.Resolved resolved = (GiftState.Resolved) value; if (resolved.getGift().getSkuId() == j && l != null && !(!m.areEqual(resolved.getGift().getSubscriptionPlanId(), l))) { z2 = false; } } if (z2) { linkedHashMap.put(entry.getKey(), entry.getValue()); } } this.knownGifts = new HashMap<>(linkedHashMap); this.knownGiftsSubject.onNext(new HashMap(this.knownGifts)); } @StoreThread private final void fetchGift(String str) { if (this.knownGifts.containsKey(str) && !(this.knownGifts.get(str) instanceof GiftState.LoadFailed)) { if (this.knownGifts.get(str) instanceof GiftState.Resolved) { GiftState giftState = this.knownGifts.get(str); Objects.requireNonNull(giftState, "null cannot be cast to non-null type com.discord.stores.StoreGifting.GiftState.Resolved"); if (((GiftState.Resolved) giftState).getGift().isComplete()) { return; } } else { return; } } setGifts(str, GiftState.Loading.INSTANCE); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().resolveGiftCode(str, true, true), false, 1, null), StoreGifting.class, (Context) null, (Function1) null, new StoreGifting$fetchGift$2(this, str), (Function0) null, (Function0) null, new StoreGifting$fetchGift$1(this, str), 54, (Object) null); } public static /* synthetic */ void generateGiftCode$default(StoreGifting storeGifting, long j, Long l, Function1 function1, Function1 function12, int i, Object obj) { storeGifting.generateGiftCode(j, (i & 2) != 0 ? null : l, (i & 4) != 0 ? null : function1, (i & 8) != 0 ? null : function12); } @StoreThread private final void removeGiftCode(String str) { this.knownGifts.remove(str); this.knownGiftsSubject.onNext(new HashMap(this.knownGifts)); } @StoreThread private final void setGifts(String str, GiftState giftState) { this.knownGifts.put(str, giftState); this.knownGiftsSubject.onNext(new HashMap(this.knownGifts)); } public final void acceptGift(ModelGift modelGift) { m.checkNotNullParameter(modelGift, "gift"); this.dispatcher.schedule(new StoreGifting$acceptGift$1(this, modelGift)); } public final void fetchMyGiftsForSku(long j, Long l) { String makeComboId = Companion.makeComboId(j, l); if (!this.knownGifts.containsKey(makeComboId) || (this.knownGifts.get(makeComboId) instanceof GiftState.LoadFailed)) { this.dispatcher.schedule(new StoreGifting$fetchMyGiftsForSku$1(this, makeComboId)); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().resolveSkuIdGift(j, l), false, 1, null), StoreGifting.class, (Context) null, (Function1) null, new StoreGifting$fetchMyGiftsForSku$2(this, makeComboId), (Function0) null, (Function0) null, new StoreGifting$fetchMyGiftsForSku$3(this, makeComboId, j, l), 54, (Object) null); } } public final void generateGiftCode(long j, Long l, Function1 function1, Function1 function12) { String makeComboId = Companion.makeComboId(j, l); if (!(this.knownGifts.get(makeComboId) instanceof GiftState.Loading)) { this.dispatcher.schedule(new StoreGifting$generateGiftCode$1(this, makeComboId)); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().generateGiftCode(new RestAPIParams.GenerateGiftCode(j, l)), false, 1, null), StoreGifting.class, (Context) null, (Function1) null, new StoreGifting$generateGiftCode$2(this, makeComboId, function12), (Function0) null, (Function0) null, new StoreGifting$generateGiftCode$3(this, makeComboId, function1), 54, (Object) null); } } public final Dispatcher getDispatcher() { return this.dispatcher; } public final HashMap getKnownGifts() { return this.knownGifts; } public final Observable> getMyResolvedGifts(long j) { Observable F = this.knownGiftsSubject.F(new StoreGifting$getMyResolvedGifts$1(j)); m.checkNotNullExpressionValue(F, "knownGiftsSubject\n … }\n }"); return F; } @StoreThread public final void handlePreLogout() { this.knownGifts.clear(); } public final Observable requestGift(String str) { m.checkNotNullParameter(str, "giftCode"); this.dispatcher.schedule(new StoreGifting$requestGift$1(this, str)); Observable q = this.knownGiftsSubject.F(new StoreGifting$requestGift$2(str)).q(); m.checkNotNullExpressionValue(q, "knownGiftsSubject\n … .distinctUntilChanged()"); return q; } public final void revokeGiftCode(ModelGift modelGift) { m.checkNotNullParameter(modelGift, "gift"); if (!this.knownGifts.containsKey(modelGift.getCode()) || !(this.knownGifts.get(modelGift.getCode()) instanceof GiftState.Revoking)) { this.dispatcher.schedule(new StoreGifting$revokeGiftCode$1(this, modelGift)); ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.restSubscribeOn$default(RestAPI.Companion.getApi().revokeGiftCode(modelGift.getCode()), false, 1, null), StoreGifting.class, (Context) null, (Function1) null, new StoreGifting$revokeGiftCode$2(this, modelGift), (Function0) null, (Function0) null, new StoreGifting$revokeGiftCode$3(this, modelGift), 54, (Object) null); } } public final void setKnownGifts(HashMap hashMap) { m.checkNotNullParameter(hashMap, ""); this.knownGifts = hashMap; } }