module TD.Data.LinkPreviewAlbumMedia
(LinkPreviewAlbumMedia(..)) 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.Photo as Photo
import qualified TD.Data.Video as Video
data LinkPreviewAlbumMedia
= LinkPreviewAlbumMediaPhoto
{ LinkPreviewAlbumMedia -> Maybe Photo
photo :: Maybe Photo.Photo
}
| LinkPreviewAlbumMediaVideo
{ LinkPreviewAlbumMedia -> Maybe Video
video :: Maybe Video.Video
}
deriving (LinkPreviewAlbumMedia -> LinkPreviewAlbumMedia -> Bool
(LinkPreviewAlbumMedia -> LinkPreviewAlbumMedia -> Bool)
-> (LinkPreviewAlbumMedia -> LinkPreviewAlbumMedia -> Bool)
-> Eq LinkPreviewAlbumMedia
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LinkPreviewAlbumMedia -> LinkPreviewAlbumMedia -> Bool
== :: LinkPreviewAlbumMedia -> LinkPreviewAlbumMedia -> Bool
$c/= :: LinkPreviewAlbumMedia -> LinkPreviewAlbumMedia -> Bool
/= :: LinkPreviewAlbumMedia -> LinkPreviewAlbumMedia -> Bool
Eq, Int -> LinkPreviewAlbumMedia -> ShowS
[LinkPreviewAlbumMedia] -> ShowS
LinkPreviewAlbumMedia -> String
(Int -> LinkPreviewAlbumMedia -> ShowS)
-> (LinkPreviewAlbumMedia -> String)
-> ([LinkPreviewAlbumMedia] -> ShowS)
-> Show LinkPreviewAlbumMedia
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LinkPreviewAlbumMedia -> ShowS
showsPrec :: Int -> LinkPreviewAlbumMedia -> ShowS
$cshow :: LinkPreviewAlbumMedia -> String
show :: LinkPreviewAlbumMedia -> String
$cshowList :: [LinkPreviewAlbumMedia] -> ShowS
showList :: [LinkPreviewAlbumMedia] -> ShowS
Show)
instance I.ShortShow LinkPreviewAlbumMedia where
shortShow :: LinkPreviewAlbumMedia -> String
shortShow LinkPreviewAlbumMediaPhoto
{ photo :: LinkPreviewAlbumMedia -> Maybe Photo
photo = Maybe Photo
photo_
}
= String
"LinkPreviewAlbumMediaPhoto"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"photo" String -> Maybe Photo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Photo
photo_
]
shortShow LinkPreviewAlbumMediaVideo
{ video :: LinkPreviewAlbumMedia -> Maybe Video
video = Maybe Video
video_
}
= String
"LinkPreviewAlbumMediaVideo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"video" String -> Maybe Video -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Video
video_
]
instance AT.FromJSON LinkPreviewAlbumMedia where
parseJSON :: Value -> Parser LinkPreviewAlbumMedia
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
"linkPreviewAlbumMediaPhoto" -> Value -> Parser LinkPreviewAlbumMedia
parseLinkPreviewAlbumMediaPhoto Value
v
String
"linkPreviewAlbumMediaVideo" -> Value -> Parser LinkPreviewAlbumMedia
parseLinkPreviewAlbumMediaVideo Value
v
String
_ -> Parser LinkPreviewAlbumMedia
forall a. Monoid a => a
mempty
where
parseLinkPreviewAlbumMediaPhoto :: A.Value -> AT.Parser LinkPreviewAlbumMedia
parseLinkPreviewAlbumMediaPhoto :: Value -> Parser LinkPreviewAlbumMedia
parseLinkPreviewAlbumMediaPhoto = String
-> (Object -> Parser LinkPreviewAlbumMedia)
-> Value
-> Parser LinkPreviewAlbumMedia
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LinkPreviewAlbumMediaPhoto" ((Object -> Parser LinkPreviewAlbumMedia)
-> Value -> Parser LinkPreviewAlbumMedia)
-> (Object -> Parser LinkPreviewAlbumMedia)
-> Value
-> Parser LinkPreviewAlbumMedia
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Photo
photo_ <- Object
o Object -> Key -> Parser (Maybe Photo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"photo"
LinkPreviewAlbumMedia -> Parser LinkPreviewAlbumMedia
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LinkPreviewAlbumMedia -> Parser LinkPreviewAlbumMedia)
-> LinkPreviewAlbumMedia -> Parser LinkPreviewAlbumMedia
forall a b. (a -> b) -> a -> b
$ LinkPreviewAlbumMediaPhoto
{ photo :: Maybe Photo
photo = Maybe Photo
photo_
}
parseLinkPreviewAlbumMediaVideo :: A.Value -> AT.Parser LinkPreviewAlbumMedia
parseLinkPreviewAlbumMediaVideo :: Value -> Parser LinkPreviewAlbumMedia
parseLinkPreviewAlbumMediaVideo = String
-> (Object -> Parser LinkPreviewAlbumMedia)
-> Value
-> Parser LinkPreviewAlbumMedia
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"LinkPreviewAlbumMediaVideo" ((Object -> Parser LinkPreviewAlbumMedia)
-> Value -> Parser LinkPreviewAlbumMedia)
-> (Object -> Parser LinkPreviewAlbumMedia)
-> Value
-> Parser LinkPreviewAlbumMedia
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Video
video_ <- Object
o Object -> Key -> Parser (Maybe Video)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"video"
LinkPreviewAlbumMedia -> Parser LinkPreviewAlbumMedia
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LinkPreviewAlbumMedia -> Parser LinkPreviewAlbumMedia)
-> LinkPreviewAlbumMedia -> Parser LinkPreviewAlbumMedia
forall a b. (a -> b) -> a -> b
$ LinkPreviewAlbumMediaVideo
{ video :: Maybe Video
video = Maybe Video
video_
}
parseJSON Value
_ = Parser LinkPreviewAlbumMedia
forall a. Monoid a => a
mempty