module TD.Data.ChatBoostSource
(ChatBoostSource(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
data ChatBoostSource
= ChatBoostSourceGiftCode
{ ChatBoostSource -> Maybe Int
user_id :: Maybe Int
, ChatBoostSource -> Maybe Text
gift_code :: Maybe T.Text
}
| ChatBoostSourceGiveaway
{ user_id :: Maybe Int
, gift_code :: Maybe T.Text
, ChatBoostSource -> Maybe Int
star_count :: Maybe Int
, ChatBoostSource -> Maybe Int
giveaway_message_id :: Maybe Int
, ChatBoostSource -> Maybe Bool
is_unclaimed :: Maybe Bool
}
| ChatBoostSourcePremium
{ user_id :: Maybe Int
}
deriving (ChatBoostSource -> ChatBoostSource -> Bool
(ChatBoostSource -> ChatBoostSource -> Bool)
-> (ChatBoostSource -> ChatBoostSource -> Bool)
-> Eq ChatBoostSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatBoostSource -> ChatBoostSource -> Bool
== :: ChatBoostSource -> ChatBoostSource -> Bool
$c/= :: ChatBoostSource -> ChatBoostSource -> Bool
/= :: ChatBoostSource -> ChatBoostSource -> Bool
Eq, Int -> ChatBoostSource -> ShowS
[ChatBoostSource] -> ShowS
ChatBoostSource -> String
(Int -> ChatBoostSource -> ShowS)
-> (ChatBoostSource -> String)
-> ([ChatBoostSource] -> ShowS)
-> Show ChatBoostSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatBoostSource -> ShowS
showsPrec :: Int -> ChatBoostSource -> ShowS
$cshow :: ChatBoostSource -> String
show :: ChatBoostSource -> String
$cshowList :: [ChatBoostSource] -> ShowS
showList :: [ChatBoostSource] -> ShowS
Show)
instance I.ShortShow ChatBoostSource where
shortShow :: ChatBoostSource -> String
shortShow ChatBoostSourceGiftCode
{ user_id :: ChatBoostSource -> Maybe Int
user_id = Maybe Int
user_id_
, gift_code :: ChatBoostSource -> Maybe Text
gift_code = Maybe Text
gift_code_
}
= String
"ChatBoostSourceGiftCode"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
, String
"gift_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
gift_code_
]
shortShow ChatBoostSourceGiveaway
{ user_id :: ChatBoostSource -> Maybe Int
user_id = Maybe Int
user_id_
, gift_code :: ChatBoostSource -> Maybe Text
gift_code = Maybe Text
gift_code_
, star_count :: ChatBoostSource -> Maybe Int
star_count = Maybe Int
star_count_
, giveaway_message_id :: ChatBoostSource -> Maybe Int
giveaway_message_id = Maybe Int
giveaway_message_id_
, is_unclaimed :: ChatBoostSource -> Maybe Bool
is_unclaimed = Maybe Bool
is_unclaimed_
}
= String
"ChatBoostSourceGiveaway"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
, String
"gift_code" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
gift_code_
, String
"star_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
star_count_
, String
"giveaway_message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
giveaway_message_id_
, String
"is_unclaimed" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_unclaimed_
]
shortShow ChatBoostSourcePremium
{ user_id :: ChatBoostSource -> Maybe Int
user_id = Maybe Int
user_id_
}
= String
"ChatBoostSourcePremium"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
user_id_
]
instance AT.FromJSON ChatBoostSource where
parseJSON :: Value -> Parser ChatBoostSource
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"chatBoostSourceGiftCode" -> Value -> Parser ChatBoostSource
parseChatBoostSourceGiftCode Value
v
String
"chatBoostSourceGiveaway" -> Value -> Parser ChatBoostSource
parseChatBoostSourceGiveaway Value
v
String
"chatBoostSourcePremium" -> Value -> Parser ChatBoostSource
parseChatBoostSourcePremium Value
v
String
_ -> Parser ChatBoostSource
forall a. Monoid a => a
mempty
where
parseChatBoostSourceGiftCode :: A.Value -> AT.Parser ChatBoostSource
parseChatBoostSourceGiftCode :: Value -> Parser ChatBoostSource
parseChatBoostSourceGiftCode = String
-> (Object -> Parser ChatBoostSource)
-> Value
-> Parser ChatBoostSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatBoostSourceGiftCode" ((Object -> Parser ChatBoostSource)
-> Value -> Parser ChatBoostSource)
-> (Object -> Parser ChatBoostSource)
-> Value
-> Parser ChatBoostSource
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"user_id"
Maybe Text
gift_code_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"gift_code"
ChatBoostSource -> Parser ChatBoostSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatBoostSource -> Parser ChatBoostSource)
-> ChatBoostSource -> Parser ChatBoostSource
forall a b. (a -> b) -> a -> b
$ ChatBoostSourceGiftCode
{ user_id :: Maybe Int
user_id = Maybe Int
user_id_
, gift_code :: Maybe Text
gift_code = Maybe Text
gift_code_
}
parseChatBoostSourceGiveaway :: A.Value -> AT.Parser ChatBoostSource
parseChatBoostSourceGiveaway :: Value -> Parser ChatBoostSource
parseChatBoostSourceGiveaway = String
-> (Object -> Parser ChatBoostSource)
-> Value
-> Parser ChatBoostSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatBoostSourceGiveaway" ((Object -> Parser ChatBoostSource)
-> Value -> Parser ChatBoostSource)
-> (Object -> Parser ChatBoostSource)
-> Value
-> Parser ChatBoostSource
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"user_id"
Maybe Text
gift_code_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"gift_code"
Maybe Int
star_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"star_count"
Maybe Int
giveaway_message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"giveaway_message_id"
Maybe Bool
is_unclaimed_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_unclaimed"
ChatBoostSource -> Parser ChatBoostSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatBoostSource -> Parser ChatBoostSource)
-> ChatBoostSource -> Parser ChatBoostSource
forall a b. (a -> b) -> a -> b
$ ChatBoostSourceGiveaway
{ user_id :: Maybe Int
user_id = Maybe Int
user_id_
, gift_code :: Maybe Text
gift_code = Maybe Text
gift_code_
, star_count :: Maybe Int
star_count = Maybe Int
star_count_
, giveaway_message_id :: Maybe Int
giveaway_message_id = Maybe Int
giveaway_message_id_
, is_unclaimed :: Maybe Bool
is_unclaimed = Maybe Bool
is_unclaimed_
}
parseChatBoostSourcePremium :: A.Value -> AT.Parser ChatBoostSource
parseChatBoostSourcePremium :: Value -> Parser ChatBoostSource
parseChatBoostSourcePremium = String
-> (Object -> Parser ChatBoostSource)
-> Value
-> Parser ChatBoostSource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatBoostSourcePremium" ((Object -> Parser ChatBoostSource)
-> Value -> Parser ChatBoostSource)
-> (Object -> Parser ChatBoostSource)
-> Value
-> Parser ChatBoostSource
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"user_id"
ChatBoostSource -> Parser ChatBoostSource
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatBoostSource -> Parser ChatBoostSource)
-> ChatBoostSource -> Parser ChatBoostSource
forall a b. (a -> b) -> a -> b
$ ChatBoostSourcePremium
{ user_id :: Maybe Int
user_id = Maybe Int
user_id_
}
parseJSON Value
_ = Parser ChatBoostSource
forall a. Monoid a => a
mempty