module TD.Data.SavedMessagesTag
(SavedMessagesTag(..)) 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
import qualified Data.Text as T
data SavedMessagesTag
= SavedMessagesTag
{ SavedMessagesTag -> Maybe ReactionType
tag :: Maybe ReactionType.ReactionType
, SavedMessagesTag -> Maybe Text
label :: Maybe T.Text
, SavedMessagesTag -> Maybe Int
count :: Maybe Int
}
deriving (SavedMessagesTag -> SavedMessagesTag -> Bool
(SavedMessagesTag -> SavedMessagesTag -> Bool)
-> (SavedMessagesTag -> SavedMessagesTag -> Bool)
-> Eq SavedMessagesTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SavedMessagesTag -> SavedMessagesTag -> Bool
== :: SavedMessagesTag -> SavedMessagesTag -> Bool
$c/= :: SavedMessagesTag -> SavedMessagesTag -> Bool
/= :: SavedMessagesTag -> SavedMessagesTag -> Bool
Eq, Int -> SavedMessagesTag -> ShowS
[SavedMessagesTag] -> ShowS
SavedMessagesTag -> String
(Int -> SavedMessagesTag -> ShowS)
-> (SavedMessagesTag -> String)
-> ([SavedMessagesTag] -> ShowS)
-> Show SavedMessagesTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SavedMessagesTag -> ShowS
showsPrec :: Int -> SavedMessagesTag -> ShowS
$cshow :: SavedMessagesTag -> String
show :: SavedMessagesTag -> String
$cshowList :: [SavedMessagesTag] -> ShowS
showList :: [SavedMessagesTag] -> ShowS
Show)
instance I.ShortShow SavedMessagesTag where
shortShow :: SavedMessagesTag -> String
shortShow SavedMessagesTag
{ tag :: SavedMessagesTag -> Maybe ReactionType
tag = Maybe ReactionType
tag_
, label :: SavedMessagesTag -> Maybe Text
label = Maybe Text
label_
, count :: SavedMessagesTag -> Maybe Int
count = Maybe Int
count_
}
= String
"SavedMessagesTag"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"tag" String -> Maybe ReactionType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ReactionType
tag_
, String
"label" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
label_
, String
"count" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
count_
]
instance AT.FromJSON SavedMessagesTag where
parseJSON :: Value -> Parser SavedMessagesTag
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
"savedMessagesTag" -> Value -> Parser SavedMessagesTag
parseSavedMessagesTag Value
v
String
_ -> Parser SavedMessagesTag
forall a. Monoid a => a
mempty
where
parseSavedMessagesTag :: A.Value -> AT.Parser SavedMessagesTag
parseSavedMessagesTag :: Value -> Parser SavedMessagesTag
parseSavedMessagesTag = String
-> (Object -> Parser SavedMessagesTag)
-> Value
-> Parser SavedMessagesTag
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SavedMessagesTag" ((Object -> Parser SavedMessagesTag)
-> Value -> Parser SavedMessagesTag)
-> (Object -> Parser SavedMessagesTag)
-> Value
-> Parser SavedMessagesTag
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe ReactionType
tag_ <- Object
o Object -> Key -> Parser (Maybe ReactionType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"tag"
Maybe Text
label_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"label"
Maybe Int
count_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"count"
SavedMessagesTag -> Parser SavedMessagesTag
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SavedMessagesTag -> Parser SavedMessagesTag)
-> SavedMessagesTag -> Parser SavedMessagesTag
forall a b. (a -> b) -> a -> b
$ SavedMessagesTag
{ tag :: Maybe ReactionType
tag = Maybe ReactionType
tag_
, label :: Maybe Text
label = Maybe Text
label_
, count :: Maybe Int
count = Maybe Int
count_
}
parseJSON Value
_ = Parser SavedMessagesTag
forall a. Monoid a => a
mempty