From 26c11d9d6b620b530500b3f6974a89b277a389fa Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 24 Feb 2026 12:37:07 +0600 Subject: [PATCH] add OwnedGifts sealed interface --- .../api/business/GetBusinessAccountGifts.kt | 5 +- .../extensions/api/gifts/GetChatGifts.kt | 5 +- .../extensions/api/gifts/GetUserGifts.kt | 5 +- tgbotapi.core/api/tgbotapi.core.api | 274 ++++++++++++++ .../GetBusinessAccountGifts.kt | 8 +- .../tgbotapi/requests/gifts/GetChatGifts.kt | 7 +- .../tgbotapi/requests/gifts/GetUserGifts.kt | 7 +- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 2 + .../dev/inmo/tgbotapi/types/OwnedGifts.kt | 4 +- .../inmo/tgbotapi/types/gifts/OwnedGift.kt | 348 ++++++++++++++++++ 10 files changed, 648 insertions(+), 17 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/OwnedGift.kt diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/business/GetBusinessAccountGifts.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/business/GetBusinessAccountGifts.kt index c28efca43e..a80eb1908e 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/business/GetBusinessAccountGifts.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/business/GetBusinessAccountGifts.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.business_connection.GetBusinessAccountGifts import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId import dev.inmo.tgbotapi.types.OwnedGifts import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceivedEvent +import dev.inmo.tgbotapi.types.gifts.OwnedGift import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlin.runCatching @@ -21,7 +22,7 @@ public suspend fun TelegramBot.getBusinessAccountGifts( sortByPrice: Boolean = false, offset: String? = null, limit: Int? = null -): OwnedGifts = execute( +): OwnedGifts = execute( GetBusinessAccountGifts( businessConnectionId, excludeUnsaved, @@ -71,7 +72,7 @@ public fun TelegramBot.getBusinessAccountGiftsFlow( initialOffset: String? = null, limit: Int? = null, onErrorContinueChecker: suspend (Throwable?) -> Boolean = { false } -): Flow> = flow { +): Flow> = flow { var currentOffset = initialOffset do { val response = runCatching { diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/GetChatGifts.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/GetChatGifts.kt index 4020bd53a5..e8df4c4db2 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/GetChatGifts.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/GetChatGifts.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.gifts.GetChatGifts import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.OwnedGifts import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceivedEvent +import dev.inmo.tgbotapi.types.gifts.OwnedGift import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -20,7 +21,7 @@ public suspend fun TelegramBot.getChatGifts( sortByPrice: Boolean = false, offset: String? = null, limit: Int? = null -): OwnedGifts = execute( +): OwnedGifts = execute( GetChatGifts( chatId, excludeUnsaved, @@ -49,7 +50,7 @@ public fun TelegramBot.getChatGiftsFlow( initialOffset: String? = null, limit: Int? = null, onErrorContinueChecker: suspend (Throwable?) -> Boolean = { false } -): Flow> = flow { +): Flow> = flow { var currentOffset = initialOffset do { val response = runCatching { diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/GetUserGifts.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/GetUserGifts.kt index 05f6e46336..f8489d79bf 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/GetUserGifts.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/gifts/GetUserGifts.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.requests.gifts.GetUserGifts import dev.inmo.tgbotapi.types.OwnedGifts import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceivedEvent +import dev.inmo.tgbotapi.types.gifts.OwnedGift import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -18,7 +19,7 @@ public suspend fun TelegramBot.getUserGifts( sortByPrice: Boolean = false, offset: String? = null, limit: Int? = null -): OwnedGifts = execute( +): OwnedGifts = execute( GetUserGifts( userId, excludeUnlimited, @@ -43,7 +44,7 @@ public fun TelegramBot.getUserGiftsFlow( initialOffset: String? = null, limit: Int? = null, onErrorContinueChecker: suspend (Throwable?) -> Boolean = { false } -): Flow> = flow { +): Flow> = flow { var currentOffset = initialOffset do { val response = runCatching { diff --git a/tgbotapi.core/api/tgbotapi.core.api b/tgbotapi.core/api/tgbotapi.core.api index d65680d25b..283ba11aaa 100644 --- a/tgbotapi.core/api/tgbotapi.core.api +++ b/tgbotapi.core/api/tgbotapi.core.api @@ -10380,6 +10380,7 @@ public final class dev/inmo/tgbotapi/types/CommonKt { public static final field callbackQueryIdField Ljava/lang/String; public static final field canAddWebPagePreviewsField Ljava/lang/String; public static final field canBeEditedField Ljava/lang/String; + public static final field canBeTransferredField Ljava/lang/String; public static final field canBeUpgradedField Ljava/lang/String; public static final field canChangeGiftSettingsField Ljava/lang/String; public static final field canChangeInfoField Ljava/lang/String; @@ -10621,6 +10622,7 @@ public final class dev/inmo/tgbotapi/types/CommonKt { public static final field isPublicField Ljava/lang/String; public static final field isRecurringField Ljava/lang/String; public static final field isRevokedField Ljava/lang/String; + public static final field isSavedField Ljava/lang/String; public static final field isStarGiveawayField Ljava/lang/String; public static final field isUnclaimedField Ljava/lang/String; public static final field isUpgradeSeparateField Ljava/lang/String; @@ -22261,6 +22263,278 @@ public final class dev/inmo/tgbotapi/types/gifts/Gifts$Companion { public final fun serializer ()Lkotlinx/serialization/KSerializer; } +public abstract interface class dev/inmo/tgbotapi/types/gifts/OwnedGift { + public static final field Companion Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Companion; + public abstract fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift; + public abstract fun getOwnedGiftId-FhTg01o ()Ljava/lang/String; + public abstract fun getSendDate ()Ldev/inmo/tgbotapi/types/TelegramDate; + public abstract fun getSenderUser ()Ldev/inmo/tgbotapi/types/chat/PreviewUser; + public abstract fun isSaved ()Z +} + +public abstract interface class dev/inmo/tgbotapi/types/gifts/OwnedGift$Common : dev/inmo/tgbotapi/types/gifts/OwnedGift { + public static final field Companion Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Common$Companion; + public fun getOwnedGiftId-FhTg01o ()Ljava/lang/String; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Common$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Common$DefaultImpls { + public static fun getOwnedGiftId-FhTg01o (Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Common;)Ljava/lang/String; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Companion : kotlinx/serialization/KSerializer { + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/gifts/OwnedGift;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public abstract interface class dev/inmo/tgbotapi/types/gifts/OwnedGift$OwnedByBusinessAccount : dev/inmo/tgbotapi/types/gifts/OwnedGift { + public static final field Companion Ldev/inmo/tgbotapi/types/gifts/OwnedGift$OwnedByBusinessAccount$Companion; + public abstract fun getOwnedGiftId-OyCYJok ()Ljava/lang/String; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$OwnedByBusinessAccount$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public abstract interface class dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular : dev/inmo/tgbotapi/abstracts/TextedInput, dev/inmo/tgbotapi/types/gifts/OwnedGift { + public static final field Companion Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Companion; + public abstract fun getCanBeUpgraded ()Z + public abstract fun getConvertStarCount ()Ljava/lang/Integer; + public abstract fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift$Regular; + public abstract fun getPrepaidUpgradeStarCount ()Ljava/lang/Integer; + public abstract fun getUniqueGiftNumber ()Ljava/lang/Integer; + public abstract fun getWasRefunded ()Z + public abstract fun isPrivate ()Z + public abstract fun isUpgradeSeparate ()Z +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common : dev/inmo/tgbotapi/types/gifts/OwnedGift$Common, dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular { + public static final field Companion Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common$Companion; + public fun (Ldev/inmo/tgbotapi/types/gifts/Gift$Regular;Ldev/inmo/tgbotapi/types/TelegramDate;Ldev/inmo/tgbotapi/types/chat/PreviewUser;Ljava/lang/String;Ljava/util/List;ZZZZLjava/lang/Integer;Ljava/lang/Integer;ZLjava/lang/Integer;)V + public synthetic fun (Ldev/inmo/tgbotapi/types/gifts/Gift$Regular;Ldev/inmo/tgbotapi/types/TelegramDate;Ldev/inmo/tgbotapi/types/chat/PreviewUser;Ljava/lang/String;Ljava/util/List;ZZZZLjava/lang/Integer;Ljava/lang/Integer;ZLjava/lang/Integer;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Ldev/inmo/tgbotapi/types/gifts/Gift$Regular; + public final fun component10 ()Ljava/lang/Integer; + public final fun component11 ()Ljava/lang/Integer; + public final fun component12 ()Z + public final fun component13 ()Ljava/lang/Integer; + public final fun component2 ()Ldev/inmo/tgbotapi/types/TelegramDate; + public final fun component3 ()Ldev/inmo/tgbotapi/types/chat/PreviewUser; + public final fun component4 ()Ljava/lang/String; + public final fun component6 ()Z + public final fun component7 ()Z + public final fun component8 ()Z + public final fun component9 ()Z + public final fun copy (Ldev/inmo/tgbotapi/types/gifts/Gift$Regular;Ldev/inmo/tgbotapi/types/TelegramDate;Ldev/inmo/tgbotapi/types/chat/PreviewUser;Ljava/lang/String;Ljava/util/List;ZZZZLjava/lang/Integer;Ljava/lang/Integer;ZLjava/lang/Integer;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common; + public static synthetic fun copy$default (Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common;Ldev/inmo/tgbotapi/types/gifts/Gift$Regular;Ldev/inmo/tgbotapi/types/TelegramDate;Ldev/inmo/tgbotapi/types/chat/PreviewUser;Ljava/lang/String;Ljava/util/List;ZZZZLjava/lang/Integer;Ljava/lang/Integer;ZLjava/lang/Integer;ILjava/lang/Object;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common; + public fun equals (Ljava/lang/Object;)Z + public fun getCanBeUpgraded ()Z + public fun getConvertStarCount ()Ljava/lang/Integer; + public fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift$Regular; + public synthetic fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift; + public fun getOwnedGiftId-FhTg01o ()Ljava/lang/String; + public fun getPrepaidUpgradeStarCount ()Ljava/lang/Integer; + public fun getSendDate ()Ldev/inmo/tgbotapi/types/TelegramDate; + public fun getSenderUser ()Ldev/inmo/tgbotapi/types/chat/PreviewUser; + public fun getText ()Ljava/lang/String; + public fun getTextSources ()Ljava/util/List; + public fun getUniqueGiftNumber ()Ljava/lang/Integer; + public fun getWasRefunded ()Z + public fun hashCode ()I + public fun isPrivate ()Z + public fun isSaved ()Z + public fun isUpgradeSeparate ()Z + public fun toString ()Ljava/lang/String; +} + +public final synthetic class dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common$$serializer; + public final fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Common$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$Companion : kotlinx/serialization/KSerializer { + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount : dev/inmo/tgbotapi/types/gifts/OwnedGift$OwnedByBusinessAccount, dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular { + public static final field Companion Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount$Companion; + public synthetic fun (Ldev/inmo/tgbotapi/types/gifts/Gift$Regular;Ldev/inmo/tgbotapi/types/TelegramDate;Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/PreviewUser;Ljava/lang/String;Ljava/util/List;ZZZZLjava/lang/Integer;Ljava/lang/Integer;ZLjava/lang/Integer;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Ldev/inmo/tgbotapi/types/gifts/Gift$Regular;Ldev/inmo/tgbotapi/types/TelegramDate;Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/PreviewUser;Ljava/lang/String;Ljava/util/List;ZZZZLjava/lang/Integer;Ljava/lang/Integer;ZLjava/lang/Integer;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Ldev/inmo/tgbotapi/types/gifts/Gift$Regular; + public final fun component10 ()Z + public final fun component11 ()Ljava/lang/Integer; + public final fun component12 ()Ljava/lang/Integer; + public final fun component13 ()Z + public final fun component14 ()Ljava/lang/Integer; + public final fun component2 ()Ldev/inmo/tgbotapi/types/TelegramDate; + public final fun component3-OyCYJok ()Ljava/lang/String; + public final fun component4 ()Ldev/inmo/tgbotapi/types/chat/PreviewUser; + public final fun component5 ()Ljava/lang/String; + public final fun component7 ()Z + public final fun component8 ()Z + public final fun component9 ()Z + public final fun copy---bBB_Q (Ldev/inmo/tgbotapi/types/gifts/Gift$Regular;Ldev/inmo/tgbotapi/types/TelegramDate;Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/PreviewUser;Ljava/lang/String;Ljava/util/List;ZZZZLjava/lang/Integer;Ljava/lang/Integer;ZLjava/lang/Integer;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount; + public static synthetic fun copy---bBB_Q$default (Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount;Ldev/inmo/tgbotapi/types/gifts/Gift$Regular;Ldev/inmo/tgbotapi/types/TelegramDate;Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/PreviewUser;Ljava/lang/String;Ljava/util/List;ZZZZLjava/lang/Integer;Ljava/lang/Integer;ZLjava/lang/Integer;ILjava/lang/Object;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount; + public fun equals (Ljava/lang/Object;)Z + public fun getCanBeUpgraded ()Z + public fun getConvertStarCount ()Ljava/lang/Integer; + public fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift$Regular; + public synthetic fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift; + public synthetic fun getOwnedGiftId-FhTg01o ()Ljava/lang/String; + public fun getOwnedGiftId-OyCYJok ()Ljava/lang/String; + public fun getPrepaidUpgradeStarCount ()Ljava/lang/Integer; + public fun getSendDate ()Ldev/inmo/tgbotapi/types/TelegramDate; + public fun getSenderUser ()Ldev/inmo/tgbotapi/types/chat/PreviewUser; + public fun getText ()Ljava/lang/String; + public fun getTextSources ()Ljava/util/List; + public fun getUniqueGiftNumber ()Ljava/lang/Integer; + public fun getWasRefunded ()Z + public fun hashCode ()I + public fun isPrivate ()Z + public fun isSaved ()Z + public fun isUpgradeSeparate ()Z + public fun toString ()Ljava/lang/String; +} + +public final synthetic class dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount$$serializer; + public final fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Regular$OwnedByBusinessAccount$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public abstract interface class dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique : dev/inmo/tgbotapi/types/gifts/OwnedGift { + public static final field Companion Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Companion; + public abstract fun getCanBeTransferred ()Z + public abstract fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift$Unique; + public abstract fun getNextTransferDate ()Ldev/inmo/tgbotapi/types/TelegramDate; + public abstract fun getTransferStarCount ()Ljava/lang/Integer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common : dev/inmo/tgbotapi/types/gifts/OwnedGift$Common, dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique { + public static final field Companion Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common$Companion; + public fun (Ldev/inmo/tgbotapi/types/gifts/Gift$Unique;Ldev/inmo/tgbotapi/types/TelegramDate;Ldev/inmo/tgbotapi/types/chat/PreviewUser;ZZLjava/lang/Integer;Ldev/inmo/tgbotapi/types/TelegramDate;)V + public synthetic fun (Ldev/inmo/tgbotapi/types/gifts/Gift$Unique;Ldev/inmo/tgbotapi/types/TelegramDate;Ldev/inmo/tgbotapi/types/chat/PreviewUser;ZZLjava/lang/Integer;Ldev/inmo/tgbotapi/types/TelegramDate;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Ldev/inmo/tgbotapi/types/gifts/Gift$Unique; + public final fun component2 ()Ldev/inmo/tgbotapi/types/TelegramDate; + public final fun component3 ()Ldev/inmo/tgbotapi/types/chat/PreviewUser; + public final fun component4 ()Z + public final fun component5 ()Z + public final fun component6 ()Ljava/lang/Integer; + public final fun component7 ()Ldev/inmo/tgbotapi/types/TelegramDate; + public final fun copy (Ldev/inmo/tgbotapi/types/gifts/Gift$Unique;Ldev/inmo/tgbotapi/types/TelegramDate;Ldev/inmo/tgbotapi/types/chat/PreviewUser;ZZLjava/lang/Integer;Ldev/inmo/tgbotapi/types/TelegramDate;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common; + public static synthetic fun copy$default (Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common;Ldev/inmo/tgbotapi/types/gifts/Gift$Unique;Ldev/inmo/tgbotapi/types/TelegramDate;Ldev/inmo/tgbotapi/types/chat/PreviewUser;ZZLjava/lang/Integer;Ldev/inmo/tgbotapi/types/TelegramDate;ILjava/lang/Object;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common; + public fun equals (Ljava/lang/Object;)Z + public fun getCanBeTransferred ()Z + public fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift$Unique; + public synthetic fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift; + public fun getNextTransferDate ()Ldev/inmo/tgbotapi/types/TelegramDate; + public fun getOwnedGiftId-FhTg01o ()Ljava/lang/String; + public fun getSendDate ()Ldev/inmo/tgbotapi/types/TelegramDate; + public fun getSenderUser ()Ldev/inmo/tgbotapi/types/chat/PreviewUser; + public fun getTransferStarCount ()Ljava/lang/Integer; + public fun hashCode ()I + public fun isSaved ()Z + public fun toString ()Ljava/lang/String; +} + +public final synthetic class dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common$$serializer; + public final fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Common$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$Companion : kotlinx/serialization/KSerializer { + public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount : dev/inmo/tgbotapi/types/gifts/OwnedGift$OwnedByBusinessAccount, dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique { + public static final field Companion Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount$Companion; + public synthetic fun (Ldev/inmo/tgbotapi/types/gifts/Gift$Unique;Ldev/inmo/tgbotapi/types/TelegramDate;Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/PreviewUser;ZZLjava/lang/Integer;Ldev/inmo/tgbotapi/types/TelegramDate;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Ldev/inmo/tgbotapi/types/gifts/Gift$Unique;Ldev/inmo/tgbotapi/types/TelegramDate;Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/PreviewUser;ZZLjava/lang/Integer;Ldev/inmo/tgbotapi/types/TelegramDate;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Ldev/inmo/tgbotapi/types/gifts/Gift$Unique; + public final fun component2 ()Ldev/inmo/tgbotapi/types/TelegramDate; + public final fun component3-OyCYJok ()Ljava/lang/String; + public final fun component4 ()Ldev/inmo/tgbotapi/types/chat/PreviewUser; + public final fun component5 ()Z + public final fun component6 ()Z + public final fun component7 ()Ljava/lang/Integer; + public final fun component8 ()Ldev/inmo/tgbotapi/types/TelegramDate; + public final fun copy-o5IlDPI (Ldev/inmo/tgbotapi/types/gifts/Gift$Unique;Ldev/inmo/tgbotapi/types/TelegramDate;Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/PreviewUser;ZZLjava/lang/Integer;Ldev/inmo/tgbotapi/types/TelegramDate;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount; + public static synthetic fun copy-o5IlDPI$default (Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount;Ldev/inmo/tgbotapi/types/gifts/Gift$Unique;Ldev/inmo/tgbotapi/types/TelegramDate;Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/PreviewUser;ZZLjava/lang/Integer;Ldev/inmo/tgbotapi/types/TelegramDate;ILjava/lang/Object;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount; + public fun equals (Ljava/lang/Object;)Z + public fun getCanBeTransferred ()Z + public fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift$Unique; + public synthetic fun getGift ()Ldev/inmo/tgbotapi/types/gifts/Gift; + public fun getNextTransferDate ()Ldev/inmo/tgbotapi/types/TelegramDate; + public synthetic fun getOwnedGiftId-FhTg01o ()Ljava/lang/String; + public fun getOwnedGiftId-OyCYJok ()Ljava/lang/String; + public fun getSendDate ()Ldev/inmo/tgbotapi/types/TelegramDate; + public fun getSenderUser ()Ldev/inmo/tgbotapi/types/chat/PreviewUser; + public fun getTransferStarCount ()Ljava/lang/Integer; + public fun hashCode ()I + public fun isSaved ()Z + public fun toString ()Ljava/lang/String; +} + +public final synthetic class dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount$$serializer : kotlinx/serialization/internal/GeneratedSerializer { + public static final field INSTANCE Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount$$serializer; + public final fun childSerializers ()[Lkotlinx/serialization/KSerializer; + public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount; + public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; + public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor; + public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Ldev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount;)V + public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V + public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer; +} + +public final class dev/inmo/tgbotapi/types/gifts/OwnedGift$Unique$OwnedByBusinessAccount$Companion { + public final fun serializer ()Lkotlinx/serialization/KSerializer; +} + public abstract interface class dev/inmo/tgbotapi/types/gifts/Rarity { public static final field Companion Ldev/inmo/tgbotapi/types/gifts/Rarity$Companion; public abstract fun getName ()Ljava/lang/String; diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/business_connection/GetBusinessAccountGifts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/business_connection/GetBusinessAccountGifts.kt index 31961b650c..7c5bbf2085 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/business_connection/GetBusinessAccountGifts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/business_connection/GetBusinessAccountGifts.kt @@ -16,10 +16,12 @@ import dev.inmo.tgbotapi.types.sortByPriceField import dev.inmo.tgbotapi.types.offsetField import dev.inmo.tgbotapi.types.limitField import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceivedEvent +import dev.inmo.tgbotapi.types.gifts.OwnedGift import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.builtins.serializer @Serializable data class GetBusinessAccountGifts( @@ -45,16 +47,16 @@ data class GetBusinessAccountGifts( val offset: String? = null, @SerialName(limitField) val limit: Int? = null, -) : BusinessRequest.Simple> { +) : BusinessRequest.Simple> { override fun method(): String = "getBusinessAccountGifts" - override val resultDeserializer: DeserializationStrategy> + override val resultDeserializer: DeserializationStrategy> get() = Companion.resultSerializer override val requestSerializer: SerializationStrategy<*> get() = serializer() companion object { @Warning("This API can be changed without any warranties of backward compatibility") - val resultSerializer = OwnedGifts.serializer(GiftSentOrReceivedEvent.ReceivedInBusinessAccount.serializer()) + val resultSerializer = OwnedGifts.serializer(OwnedGift.OwnedByBusinessAccount.serializer()) } } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/gifts/GetChatGifts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/gifts/GetChatGifts.kt index d9759d7752..b48c91e2ad 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/gifts/GetChatGifts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/gifts/GetChatGifts.kt @@ -15,6 +15,7 @@ import dev.inmo.tgbotapi.types.excludeFromBlockchainField import dev.inmo.tgbotapi.types.excludeUniqueField import dev.inmo.tgbotapi.types.sortByPriceField import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceivedEvent +import dev.inmo.tgbotapi.types.gifts.OwnedGift import dev.inmo.tgbotapi.types.limitField import dev.inmo.tgbotapi.types.offsetField import kotlinx.serialization.DeserializationStrategy @@ -46,16 +47,16 @@ data class GetChatGifts( val offset: String? = null, @SerialName(limitField) val limit: Int? = null, -) : SimpleRequest>, ChatRequest { +) : SimpleRequest>, ChatRequest { override fun method(): String = "getChatGifts" - override val resultDeserializer: DeserializationStrategy> + override val resultDeserializer: DeserializationStrategy> get() = Companion.resultSerializer override val requestSerializer: SerializationStrategy<*> get() = serializer() companion object { @Warning("This API can be changed without any warranties of backward compatibility") - val resultSerializer = OwnedGifts.serializer(GiftSentOrReceivedEvent.serializer()) + val resultSerializer = OwnedGifts.serializer(OwnedGift.Common.serializer()) } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/gifts/GetUserGifts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/gifts/GetUserGifts.kt index 8a6edcdda7..5ca40bee63 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/gifts/GetUserGifts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/gifts/GetUserGifts.kt @@ -11,6 +11,7 @@ import dev.inmo.tgbotapi.types.excludeFromBlockchainField import dev.inmo.tgbotapi.types.excludeUniqueField import dev.inmo.tgbotapi.types.sortByPriceField import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceivedEvent +import dev.inmo.tgbotapi.types.gifts.OwnedGift import dev.inmo.tgbotapi.types.limitField import dev.inmo.tgbotapi.types.offsetField import dev.inmo.tgbotapi.types.userIdField @@ -40,16 +41,16 @@ data class GetUserGifts( val offset: String? = null, @SerialName(limitField) val limit: Int? = null, -) : SimpleRequest> { +) : SimpleRequest> { override fun method(): String = "getUserGifts" - override val resultDeserializer: DeserializationStrategy> + override val resultDeserializer: DeserializationStrategy> get() = Companion.resultSerializer override val requestSerializer: SerializationStrategy<*> get() = serializer() companion object { @Warning("This API can be changed without any warranties of backward compatibility") - val resultSerializer = OwnedGifts.serializer(GiftSentOrReceivedEvent.serializer()) + val resultSerializer = OwnedGifts.serializer(OwnedGift.Common.serializer()) } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 00aa53c72a..414d72e1be 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -759,7 +759,9 @@ const val personalRemainingCountField = "personal_remaining_count" const val hasColorsField = "has_colors" const val uniqueGiftVariantCountField = "unique_gift_variant_count" const val uniqueGiftNumberField = "unique_gift_number" +const val isSavedField = "is_saved" const val isUpgradeSeparateField = "is_upgrade_separate" +const val canBeTransferredField = "can_be_transferred" const val isFromBlockchainField = "is_from_blockchain" const val centerColorField = "center_color" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/OwnedGifts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/OwnedGifts.kt index 3be69f833b..13132f285a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/OwnedGifts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/OwnedGifts.kt @@ -1,11 +1,11 @@ package dev.inmo.tgbotapi.types -import dev.inmo.tgbotapi.types.gifts.GiftSentOrReceivedEvent +import dev.inmo.tgbotapi.types.gifts.OwnedGift import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class OwnedGifts( +data class OwnedGifts( @SerialName(totalCountField) val totalCount: Int, @SerialName(giftsField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/OwnedGift.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/OwnedGift.kt new file mode 100644 index 0000000000..5eb9746848 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/gifts/OwnedGift.kt @@ -0,0 +1,348 @@ +package dev.inmo.tgbotapi.types.gifts + +import dev.inmo.tgbotapi.abstracts.TextedInput +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.PreviewUser +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent +import dev.inmo.tgbotapi.types.message.RawMessageEntities +import dev.inmo.tgbotapi.types.message.asTextSources +import dev.inmo.tgbotapi.types.message.textsources.TextSource +import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.message.toRawMessageEntities +import dev.inmo.tgbotapi.types.payments.abstracts.Currency +import kotlinx.serialization.KSerializer +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient +import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.JsonDecoder +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive +import kotlin.jvm.JvmInline +import kotlin.jvm.JvmName + +@Serializable(OwnedGift.Companion::class) +sealed interface OwnedGift { + val gift: Gift + val sendDate: TelegramDate + val ownedGiftId: GiftId? + val senderUser: PreviewUser? + val isSaved: Boolean + + @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") + @Serializable(OwnedGift.Companion::class) + sealed interface OwnedByBusinessAccount : OwnedGift { + override val ownedGiftId: GiftId + } + + @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") + @Serializable(OwnedGift.Companion::class) + sealed interface Common : OwnedGift { + override val ownedGiftId: GiftId? + get() = null + } + + @Serializable(Regular.Companion::class) + sealed interface Regular : OwnedGift, TextedInput { + override val gift: Gift.Regular + val isPrivate: Boolean + val canBeUpgraded: Boolean + val wasRefunded: Boolean + val convertStarCount: Int? + val prepaidUpgradeStarCount: Int? + val isUpgradeSeparate: Boolean + val uniqueGiftNumber: Int? + + @Serializable + data class Common( + @SerialName(giftField) + override val gift: Gift.Regular, + @SerialName(sendDateField) + override val sendDate: TelegramDate, + @SerialName(senderUserField) + override val senderUser: PreviewUser? = null, + @SerialName(textField) + override val text: String? = null, + @SerialName(entitiesField) + private val entities: RawMessageEntities? = null, + @SerialName(isPrivateField) + override val isPrivate: Boolean = false, + @SerialName(isSavedField) + override val isSaved: Boolean = false, + @SerialName(canBeUpgradedField) + override val canBeUpgraded: Boolean = false, + @SerialName(wasRefundedField) + override val wasRefunded: Boolean = false, + @SerialName(convertStarCountField) + override val convertStarCount: Int? = null, + @SerialName(prepaidUpgradeStarCountField) + override val prepaidUpgradeStarCount: Int? = null, + @SerialName(isUpgradeSeparateField) + override val isUpgradeSeparate: Boolean = false, + @SerialName(uniqueGiftNumberField) + override val uniqueGiftNumber: Int? = null + ) : Regular, OwnedGift.Common { + override val textSources: List by lazy { + entities ?.asTextSources(text ?: return@lazy emptyList()) ?: emptyList() + } + } + + @Serializable + data class OwnedByBusinessAccount( + @SerialName(giftField) + override val gift: Gift.Regular, + @SerialName(sendDateField) + override val sendDate: TelegramDate, + @SerialName(ownedGiftIdField) + override val ownedGiftId: GiftId, + @SerialName(senderUserField) + override val senderUser: PreviewUser? = null, + @SerialName(textField) + override val text: String? = null, + @SerialName(entitiesField) + private val entities: RawMessageEntities? = null, + @SerialName(isPrivateField) + override val isPrivate: Boolean = false, + @SerialName(isSavedField) + override val isSaved: Boolean = false, + @SerialName(canBeUpgradedField) + override val canBeUpgraded: Boolean = false, + @SerialName(wasRefundedField) + override val wasRefunded: Boolean = false, + @SerialName(convertStarCountField) + override val convertStarCount: Int? = null, + @SerialName(prepaidUpgradeStarCountField) + override val prepaidUpgradeStarCount: Int? = null, + @SerialName(isUpgradeSeparateField) + override val isUpgradeSeparate: Boolean = false, + @SerialName(uniqueGiftNumberField) + override val uniqueGiftNumber: Int? = null + ) : Regular, OwnedGift.OwnedByBusinessAccount { + override val textSources: List by lazy { + entities ?.asTextSources(text ?: return@lazy emptyList()) ?: emptyList() + } + } + + companion object : KSerializer { + @Serializable + private data class Surrogate( + @SerialName(giftField) + val gift: Gift.Regular, + @SerialName(ownedGiftIdField) + val ownedGiftId: GiftId? = null, + @SerialName(senderUserField) + val senderUser: PreviewUser? = null, + @SerialName(sendDateField) + val sendDate: TelegramDate, + @SerialName(textField) + val text: String? = null, + @SerialName(entitiesField) + val entities: RawMessageEntities? = null, + @SerialName(isPrivateField) + val isPrivate: Boolean = false, + @SerialName(isSavedField) + val isSaved: Boolean = false, + @SerialName(canBeUpgradedField) + val canBeUpgraded: Boolean = false, + @SerialName(wasRefundedField) + val wasRefunded: Boolean = false, + @SerialName(convertStarCountField) + val convertStarCount: Int? = null, + @SerialName(prepaidUpgradeStarCountField) + val prepaidUpgradeStarCount: Int? = null, + @SerialName(isUpgradeSeparateField) + val isUpgradeSeparate: Boolean = false, + @SerialName(uniqueGiftNumberField) + val uniqueGiftNumber: Int? = null + ) + + override val descriptor: SerialDescriptor + get() = Surrogate.serializer().descriptor + + override fun serialize(encoder: Encoder, value: Regular) { + when (value) { + is Common -> Common.serializer().serialize(encoder, value) + is OwnedByBusinessAccount -> OwnedByBusinessAccount.serializer().serialize(encoder, value) + } + } + + override fun deserialize(decoder: Decoder): Regular { + val surrogate = Surrogate.serializer().deserialize(decoder) + + return when { + surrogate.ownedGiftId == null -> { + Common( + gift = surrogate.gift, + sendDate = surrogate.sendDate, + senderUser = surrogate.senderUser, + text = surrogate.text, + entities = surrogate.entities, + isPrivate = surrogate.isPrivate, + isSaved = surrogate.isSaved, + canBeUpgraded = surrogate.canBeUpgraded, + wasRefunded = surrogate.wasRefunded, + convertStarCount = surrogate.convertStarCount, + prepaidUpgradeStarCount = surrogate.prepaidUpgradeStarCount, + isUpgradeSeparate = surrogate.isUpgradeSeparate, + uniqueGiftNumber = surrogate.uniqueGiftNumber + ) + } + else -> { + OwnedByBusinessAccount( + gift = surrogate.gift, + sendDate = surrogate.sendDate, + ownedGiftId = surrogate.ownedGiftId, + senderUser = surrogate.senderUser, + text = surrogate.text, + entities = surrogate.entities, + isPrivate = surrogate.isPrivate, + isSaved = surrogate.isSaved, + canBeUpgraded = surrogate.canBeUpgraded, + wasRefunded = surrogate.wasRefunded, + convertStarCount = surrogate.convertStarCount, + prepaidUpgradeStarCount = surrogate.prepaidUpgradeStarCount, + isUpgradeSeparate = surrogate.isUpgradeSeparate, + uniqueGiftNumber = surrogate.uniqueGiftNumber + ) + } + } + } + } + } + + @Serializable(Unique.Companion::class) + sealed interface Unique : OwnedGift { + override val gift: Gift.Unique + val canBeTransferred: Boolean + val transferStarCount: Int? + val nextTransferDate: TelegramDate? + + @Serializable + data class Common( + @SerialName(giftField) + override val gift: Gift.Unique, + @SerialName(sendDateField) + override val sendDate: TelegramDate, + @SerialName(senderUserField) + override val senderUser: PreviewUser? = null, + @SerialName(isSavedField) + override val isSaved: Boolean = false, + @SerialName(canBeTransferredField) + override val canBeTransferred: Boolean = false, + @SerialName(transferStarCountField) + override val transferStarCount: Int? = null, + @SerialName(nextTransferDateField) + override val nextTransferDate: TelegramDate? = null + ) : Unique, OwnedGift.Common + + @Serializable + data class OwnedByBusinessAccount( + @SerialName(giftField) + override val gift: Gift.Unique, + @SerialName(sendDateField) + override val sendDate: TelegramDate, + @SerialName(ownedGiftIdField) + override val ownedGiftId: GiftId, + @SerialName(senderUserField) + override val senderUser: PreviewUser? = null, + @SerialName(isSavedField) + override val isSaved: Boolean = false, + @SerialName(canBeTransferredField) + override val canBeTransferred: Boolean = false, + @SerialName(transferStarCountField) + override val transferStarCount: Int? = null, + @SerialName(nextTransferDateField) + override val nextTransferDate: TelegramDate? = null + ) : Unique, OwnedGift.OwnedByBusinessAccount + + companion object : KSerializer { + @Serializable + private data class Surrogate( + @SerialName(giftField) + val gift: Gift.Unique, + @SerialName(ownedGiftIdField) + val ownedGiftId: GiftId? = null, + @SerialName(senderUserField) + val senderUser: PreviewUser? = null, + @SerialName(sendDateField) + val sendDate: TelegramDate, + @SerialName(isSavedField) + val isSaved: Boolean = false, + @SerialName(canBeTransferredField) + val canBeTransferred: Boolean = false, + @SerialName(transferStarCountField) + val transferStarCount: Int? = null, + @SerialName(nextTransferDateField) + val nextTransferDate: TelegramDate? = null + ) + + override val descriptor: SerialDescriptor + get() = Surrogate.serializer().descriptor + + override fun serialize(encoder: Encoder, value: Unique) { + when (value) { + is Common -> Common.serializer().serialize(encoder, value) + is OwnedByBusinessAccount -> OwnedByBusinessAccount.serializer().serialize(encoder, value) + } + } + + override fun deserialize(decoder: Decoder): Unique { + val surrogate = Surrogate.serializer().deserialize(decoder) + + return when { + surrogate.ownedGiftId == null -> { + Common( + gift = surrogate.gift, + sendDate = surrogate.sendDate, + senderUser = surrogate.senderUser, + isSaved = surrogate.isSaved, + canBeTransferred = surrogate.canBeTransferred, + transferStarCount = surrogate.transferStarCount, + nextTransferDate = surrogate.nextTransferDate + ) + } + else -> { + OwnedByBusinessAccount( + gift = surrogate.gift, + sendDate = surrogate.sendDate, + ownedGiftId = surrogate.ownedGiftId, + senderUser = surrogate.senderUser, + isSaved = surrogate.isSaved, + canBeTransferred = surrogate.canBeTransferred, + transferStarCount = surrogate.transferStarCount, + nextTransferDate = surrogate.nextTransferDate + ) + } + } + } + } + } + + companion object : KSerializer { + override val descriptor: SerialDescriptor + get() = JsonElement.serializer().descriptor + + override fun serialize(encoder: Encoder, value: OwnedGift) { + when (value) { + is Regular -> Regular.serialize(encoder, value) + is Unique -> Unique.serialize(encoder, value) + } + } + + override fun deserialize(decoder: Decoder): OwnedGift { + val json = (decoder as JsonDecoder) + val element = json.decodeJsonElement() + val type = element.jsonObject[typeField] ?.jsonPrimitive ?.content + + return when (type) { + "regular" -> json.json.decodeFromJsonElement(Regular, element) + "unique" -> json.json.decodeFromJsonElement(Unique, element) + else -> error("Unknown OwnedGift type: $type") + } + } + } +}