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