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