diff --git a/src/TgBotLib/Enums/Types/ChatBoostSourceType.php b/src/TgBotLib/Enums/Types/ChatBoostSourceType.php new file mode 100644 index 0000000..4a1f1d7 --- /dev/null +++ b/src/TgBotLib/Enums/Types/ChatBoostSourceType.php @@ -0,0 +1,10 @@ +source; + } + + /** + * @inheritDoc + */ + public abstract function toArray(): ?array; + + /** + * @inheritDoc + */ + public static function fromArray(?array $data): ?ChatBoostSource + { + if($data === null) + { + return null; + } + + return match (ChatBoostSourceType::tryFrom($data['source'])) + { + ChatBoostSourceType::GIFT_CODE => ChatBoostSourceGiftCode::fromArray($data), + ChatBoostSourceType::PREMIUM => ChatBoostSourcePremium::fromArray($data), + ChatBoostSourceType::GIVEAWAY => ChatBoostSourceGiveaway::fromArray($data), + default => throw new InvalidArgumentException('Unknown source type') + }; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/ChatBoostSource/ChatBoostSourceGiftCode.php b/src/TgBotLib/Objects/ChatBoostSource/ChatBoostSourceGiftCode.php new file mode 100644 index 0000000..63aa409 --- /dev/null +++ b/src/TgBotLib/Objects/ChatBoostSource/ChatBoostSourceGiftCode.php @@ -0,0 +1,51 @@ +user; + } + + /** + * @inheritDoc + */ + public function toArray(): array + { + return [ + 'source' => $this->source->value, + 'user' => $this->user->toArray() + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(?array $data): ?ChatBoostSourceGiftCode + { + if($data === null) + { + return null; + } + + $object = new self(); + $object->source = ChatBoostSourceType::PREMIUM; + $object->user = User::fromArray($data['user']); + + return $object; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/ChatBoostSource/ChatBoostSourceGiveaway.php b/src/TgBotLib/Objects/ChatBoostSource/ChatBoostSourceGiveaway.php new file mode 100644 index 0000000..81fae9e --- /dev/null +++ b/src/TgBotLib/Objects/ChatBoostSource/ChatBoostSourceGiveaway.php @@ -0,0 +1,91 @@ +giveaway_message_id; + } + + /** + * Optional. User that won the prize in the giveaway if any; for Telegram Premium giveaways only + * + * @return User|null + */ + public function getUser(): ?User + { + return $this->user; + } + + /** + * Optional. The number of Telegram Stars to be split between giveaway winners; for Telegram Star giveaways only + * + * @return int|null + */ + public function getPrizeStarCount(): ?int + { + return $this->prize_star_count; + } + + /** + * Optional. True, if the giveaway was completed, but there was no user to win the prize + * + * @return bool + */ + public function isIsUnclaimed(): bool + { + return $this->is_unclaimed; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->source->value, + 'giveaway_message_id' => $this->giveaway_message_id, + 'user' => $this->user?->toArray(), + 'prize_star_count' => $this->prize_star_count, + 'is_unclaimed' => $this->is_unclaimed + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(?array $data): ?ChatBoostSourceGiveaway + { + if($data === null) + { + return null; + } + + $object = new self(); + $object->source = ChatBoostSourceType::GIVEAWAY; + $object->giveaway_message_id = $data['giveaway_message_id']; + $object->user = User::fromArray($data['user']); + $object->prize_star_count = $data['prize_star_count']; + $object->is_unclaimed = $data['is_unclaimed']; + + return $object; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/ChatBoostSource/ChatBoostSourcePremium.php b/src/TgBotLib/Objects/ChatBoostSource/ChatBoostSourcePremium.php new file mode 100644 index 0000000..577ac6f --- /dev/null +++ b/src/TgBotLib/Objects/ChatBoostSource/ChatBoostSourcePremium.php @@ -0,0 +1,51 @@ +user; + } + + /** + * @inheritDoc + */ + public function toArray(): array + { + return [ + 'source' => $this->source->value, + 'user' => $this->user?->toArray() + ]; + } + + /** + * @inheritDoc + */ + public static function fromArray(?array $data): ?ChatBoostSourcePremium + { + if($data === null) + { + return null; + } + + $object = new self(); + $object->source = ChatBoostSourceType::PREMIUM; + $object->user = User::fromArray($data['user']); + + return $object; + } + } \ No newline at end of file