module TD.Data.ChatPhotoInfo
(ChatPhotoInfo(..)) 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.File as File
import qualified TD.Data.Minithumbnail as Minithumbnail
data ChatPhotoInfo
= ChatPhotoInfo
{ ChatPhotoInfo -> Maybe File
small :: Maybe File.File
, ChatPhotoInfo -> Maybe File
big :: Maybe File.File
, ChatPhotoInfo -> Maybe Minithumbnail
minithumbnail :: Maybe Minithumbnail.Minithumbnail
, ChatPhotoInfo -> Maybe Bool
has_animation :: Maybe Bool
, ChatPhotoInfo -> Maybe Bool
is_personal :: Maybe Bool
}
deriving (ChatPhotoInfo -> ChatPhotoInfo -> Bool
(ChatPhotoInfo -> ChatPhotoInfo -> Bool)
-> (ChatPhotoInfo -> ChatPhotoInfo -> Bool) -> Eq ChatPhotoInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ChatPhotoInfo -> ChatPhotoInfo -> Bool
== :: ChatPhotoInfo -> ChatPhotoInfo -> Bool
$c/= :: ChatPhotoInfo -> ChatPhotoInfo -> Bool
/= :: ChatPhotoInfo -> ChatPhotoInfo -> Bool
Eq, Int -> ChatPhotoInfo -> ShowS
[ChatPhotoInfo] -> ShowS
ChatPhotoInfo -> String
(Int -> ChatPhotoInfo -> ShowS)
-> (ChatPhotoInfo -> String)
-> ([ChatPhotoInfo] -> ShowS)
-> Show ChatPhotoInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChatPhotoInfo -> ShowS
showsPrec :: Int -> ChatPhotoInfo -> ShowS
$cshow :: ChatPhotoInfo -> String
show :: ChatPhotoInfo -> String
$cshowList :: [ChatPhotoInfo] -> ShowS
showList :: [ChatPhotoInfo] -> ShowS
Show)
instance I.ShortShow ChatPhotoInfo where
shortShow :: ChatPhotoInfo -> String
shortShow ChatPhotoInfo
{ small :: ChatPhotoInfo -> Maybe File
small = Maybe File
small_
, big :: ChatPhotoInfo -> Maybe File
big = Maybe File
big_
, minithumbnail :: ChatPhotoInfo -> Maybe Minithumbnail
minithumbnail = Maybe Minithumbnail
minithumbnail_
, has_animation :: ChatPhotoInfo -> Maybe Bool
has_animation = Maybe Bool
has_animation_
, is_personal :: ChatPhotoInfo -> Maybe Bool
is_personal = Maybe Bool
is_personal_
}
= String
"ChatPhotoInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"small" String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
small_
, String
"big" String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
big_
, String
"minithumbnail" String -> Maybe Minithumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Minithumbnail
minithumbnail_
, String
"has_animation" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
has_animation_
, String
"is_personal" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_personal_
]
instance AT.FromJSON ChatPhotoInfo where
parseJSON :: Value -> Parser ChatPhotoInfo
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
"chatPhotoInfo" -> Value -> Parser ChatPhotoInfo
parseChatPhotoInfo Value
v
String
_ -> Parser ChatPhotoInfo
forall a. Monoid a => a
mempty
where
parseChatPhotoInfo :: A.Value -> AT.Parser ChatPhotoInfo
parseChatPhotoInfo :: Value -> Parser ChatPhotoInfo
parseChatPhotoInfo = String
-> (Object -> Parser ChatPhotoInfo)
-> Value
-> Parser ChatPhotoInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ChatPhotoInfo" ((Object -> Parser ChatPhotoInfo) -> Value -> Parser ChatPhotoInfo)
-> (Object -> Parser ChatPhotoInfo)
-> Value
-> Parser ChatPhotoInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe File
small_ <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"small"
Maybe File
big_ <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"big"
Maybe Minithumbnail
minithumbnail_ <- Object
o Object -> Key -> Parser (Maybe Minithumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"minithumbnail"
Maybe Bool
has_animation_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"has_animation"
Maybe Bool
is_personal_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_personal"
ChatPhotoInfo -> Parser ChatPhotoInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChatPhotoInfo -> Parser ChatPhotoInfo)
-> ChatPhotoInfo -> Parser ChatPhotoInfo
forall a b. (a -> b) -> a -> b
$ ChatPhotoInfo
{ small :: Maybe File
small = Maybe File
small_
, big :: Maybe File
big = Maybe File
big_
, minithumbnail :: Maybe Minithumbnail
minithumbnail = Maybe Minithumbnail
minithumbnail_
, has_animation :: Maybe Bool
has_animation = Maybe Bool
has_animation_
, is_personal :: Maybe Bool
is_personal = Maybe Bool
is_personal_
}
parseJSON Value
_ = Parser ChatPhotoInfo
forall a. Monoid a => a
mempty