module TD.Data.ChatAvailableReactions
(ChatAvailableReactions(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.ReactionType as ReactionType
data ChatAvailableReactions
= ChatAvailableReactionsAll
{ ChatAvailableReactions -> Maybe Int
max_reaction_count :: Maybe Int
}
| ChatAvailableReactionsSome
{ ChatAvailableReactions -> Maybe [ReactionType]
reactions :: Maybe [ReactionType.ReactionType]
, max_reaction_count :: Maybe Int
}
deriving (ChatAvailableReactions -> ChatAvailableReactions -> Bool
(ChatAvailableReactions -> ChatAvailableReactions -> Bool)
-> (ChatAvailableReactions -> ChatAvailableReactions -> Bool)
-> Eq ChatAvailableReactions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatAvailableReactions -> ChatAvailableReactions -> Bool
== :: ChatAvailableReactions -> ChatAvailableReactions -> Bool
$c/= :: ChatAvailableReactions -> ChatAvailableReactions -> Bool
/= :: ChatAvailableReactions -> ChatAvailableReactions -> Bool
Eq, Int -> ChatAvailableReactions -> ShowS
[ChatAvailableReactions] -> ShowS
ChatAvailableReactions -> String
(Int -> ChatAvailableReactions -> ShowS)
-> (ChatAvailableReactions -> String)
-> ([ChatAvailableReactions] -> ShowS)
-> Show ChatAvailableReactions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatAvailableReactions -> ShowS
showsPrec :: Int -> ChatAvailableReactions -> ShowS
$cshow :: ChatAvailableReactions -> String
show :: ChatAvailableReactions -> String
$cshowList :: [ChatAvailableReactions] -> ShowS
showList :: [ChatAvailableReactions] -> ShowS
Show)
instance I.ShortShow ChatAvailableReactions where
shortShow :: ChatAvailableReactions -> String
shortShow ChatAvailableReactionsAll
{ max_reaction_count :: ChatAvailableReactions -> Maybe Int
max_reaction_count = Maybe Int
max_reaction_count_
}
= String
"ChatAvailableReactionsAll"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"max_reaction_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
max_reaction_count_
]
shortShow ChatAvailableReactionsSome
{ reactions :: ChatAvailableReactions -> Maybe [ReactionType]
reactions = Maybe [ReactionType]
reactions_
, max_reaction_count :: ChatAvailableReactions -> Maybe Int
max_reaction_count = Maybe Int
max_reaction_count_
}
= String
"ChatAvailableReactionsSome"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"reactions" String -> Maybe [ReactionType] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [ReactionType]
reactions_
, String
"max_reaction_count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
max_reaction_count_
]
instance AT.FromJSON ChatAvailableReactions where
parseJSON :: Value -> Parser ChatAvailableReactions
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
"chatAvailableReactionsAll" -> Value -> Parser ChatAvailableReactions
parseChatAvailableReactionsAll Value
v
String
"chatAvailableReactionsSome" -> Value -> Parser ChatAvailableReactions
parseChatAvailableReactionsSome Value
v
String
_ -> Parser ChatAvailableReactions
forall a. Monoid a => a
mempty
where
parseChatAvailableReactionsAll :: A.Value -> AT.Parser ChatAvailableReactions
parseChatAvailableReactionsAll :: Value -> Parser ChatAvailableReactions
parseChatAvailableReactionsAll = String
-> (Object -> Parser ChatAvailableReactions)
-> Value
-> Parser ChatAvailableReactions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatAvailableReactionsAll" ((Object -> Parser ChatAvailableReactions)
-> Value -> Parser ChatAvailableReactions)
-> (Object -> Parser ChatAvailableReactions)
-> Value
-> Parser ChatAvailableReactions
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
max_reaction_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"max_reaction_count"
ChatAvailableReactions -> Parser ChatAvailableReactions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatAvailableReactions -> Parser ChatAvailableReactions)
-> ChatAvailableReactions -> Parser ChatAvailableReactions
forall a b. (a -> b) -> a -> b
$ ChatAvailableReactionsAll
{ max_reaction_count :: Maybe Int
max_reaction_count = Maybe Int
max_reaction_count_
}
parseChatAvailableReactionsSome :: A.Value -> AT.Parser ChatAvailableReactions
parseChatAvailableReactionsSome :: Value -> Parser ChatAvailableReactions
parseChatAvailableReactionsSome = String
-> (Object -> Parser ChatAvailableReactions)
-> Value
-> Parser ChatAvailableReactions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatAvailableReactionsSome" ((Object -> Parser ChatAvailableReactions)
-> Value -> Parser ChatAvailableReactions)
-> (Object -> Parser ChatAvailableReactions)
-> Value
-> Parser ChatAvailableReactions
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [ReactionType]
reactions_ <- Object
o Object -> Key -> Parser (Maybe [ReactionType])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"reactions"
Maybe Int
max_reaction_count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"max_reaction_count"
ChatAvailableReactions -> Parser ChatAvailableReactions
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatAvailableReactions -> Parser ChatAvailableReactions)
-> ChatAvailableReactions -> Parser ChatAvailableReactions
forall a b. (a -> b) -> a -> b
$ ChatAvailableReactionsSome
{ reactions :: Maybe [ReactionType]
reactions = Maybe [ReactionType]
reactions_
, max_reaction_count :: Maybe Int
max_reaction_count = Maybe Int
max_reaction_count_
}
parseJSON Value
_ = Parser ChatAvailableReactions
forall a. Monoid a => a
mempty
instance AT.ToJSON ChatAvailableReactions where
toJSON :: ChatAvailableReactions -> Value
toJSON ChatAvailableReactionsAll
{ max_reaction_count :: ChatAvailableReactions -> Maybe Int
max_reaction_count = Maybe Int
max_reaction_count_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatAvailableReactionsAll"
, Key
"max_reaction_count" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
max_reaction_count_
]
toJSON ChatAvailableReactionsSome
{ reactions :: ChatAvailableReactions -> Maybe [ReactionType]
reactions = Maybe [ReactionType]
reactions_
, max_reaction_count :: ChatAvailableReactions -> Maybe Int
max_reaction_count = Maybe Int
max_reaction_count_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"chatAvailableReactionsSome"
, Key
"reactions" Key -> Maybe [ReactionType] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [ReactionType]
reactions_
, Key
"max_reaction_count" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
max_reaction_count_
]