module TD.Data.PaidMedia
(PaidMedia(..)) 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.Minithumbnail as Minithumbnail
import qualified TD.Data.Photo as Photo
import qualified TD.Data.Video as Video
data PaidMedia
= PaidMediaPreview
{ PaidMedia -> Maybe Int
width :: Maybe Int
, PaidMedia -> Maybe Int
height :: Maybe Int
, PaidMedia -> Maybe Int
duration :: Maybe Int
, PaidMedia -> Maybe Minithumbnail
minithumbnail :: Maybe Minithumbnail.Minithumbnail
}
| PaidMediaPhoto
{ PaidMedia -> Maybe Photo
photo :: Maybe Photo.Photo
}
| PaidMediaVideo
{ PaidMedia -> Maybe Video
video :: Maybe Video.Video
}
| PaidMediaUnsupported
deriving (PaidMedia -> PaidMedia -> Bool
(PaidMedia -> PaidMedia -> Bool)
-> (PaidMedia -> PaidMedia -> Bool) -> Eq PaidMedia
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PaidMedia -> PaidMedia -> Bool
== :: PaidMedia -> PaidMedia -> Bool
$c/= :: PaidMedia -> PaidMedia -> Bool
/= :: PaidMedia -> PaidMedia -> Bool
Eq, Int -> PaidMedia -> ShowS
[PaidMedia] -> ShowS
PaidMedia -> String
(Int -> PaidMedia -> ShowS)
-> (PaidMedia -> String)
-> ([PaidMedia] -> ShowS)
-> Show PaidMedia
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PaidMedia -> ShowS
showsPrec :: Int -> PaidMedia -> ShowS
$cshow :: PaidMedia -> String
show :: PaidMedia -> String
$cshowList :: [PaidMedia] -> ShowS
showList :: [PaidMedia] -> ShowS
Show)
instance I.ShortShow PaidMedia where
shortShow :: PaidMedia -> String
shortShow PaidMediaPreview
{ width :: PaidMedia -> Maybe Int
width = Maybe Int
width_
, height :: PaidMedia -> Maybe Int
height = Maybe Int
height_
, duration :: PaidMedia -> Maybe Int
duration = Maybe Int
duration_
, minithumbnail :: PaidMedia -> Maybe Minithumbnail
minithumbnail = Maybe Minithumbnail
minithumbnail_
}
= String
"PaidMediaPreview"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"width" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
width_
, String
"height" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
height_
, String
"duration" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
duration_
, String
"minithumbnail" String -> Maybe Minithumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Minithumbnail
minithumbnail_
]
shortShow PaidMediaPhoto
{ photo :: PaidMedia -> Maybe Photo
photo = Maybe Photo
photo_
}
= String
"PaidMediaPhoto"
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 PaidMediaVideo
{ video :: PaidMedia -> Maybe Video
video = Maybe Video
video_
}
= String
"PaidMediaVideo"
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_
]
shortShow PaidMedia
PaidMediaUnsupported
= String
"PaidMediaUnsupported"
instance AT.FromJSON PaidMedia where
parseJSON :: Value -> Parser PaidMedia
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
"paidMediaPreview" -> Value -> Parser PaidMedia
parsePaidMediaPreview Value
v
String
"paidMediaPhoto" -> Value -> Parser PaidMedia
parsePaidMediaPhoto Value
v
String
"paidMediaVideo" -> Value -> Parser PaidMedia
parsePaidMediaVideo Value
v
String
"paidMediaUnsupported" -> PaidMedia -> Parser PaidMedia
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure PaidMedia
PaidMediaUnsupported
String
_ -> Parser PaidMedia
forall a. Monoid a => a
mempty
where
parsePaidMediaPreview :: A.Value -> AT.Parser PaidMedia
parsePaidMediaPreview :: Value -> Parser PaidMedia
parsePaidMediaPreview = String -> (Object -> Parser PaidMedia) -> Value -> Parser PaidMedia
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaidMediaPreview" ((Object -> Parser PaidMedia) -> Value -> Parser PaidMedia)
-> (Object -> Parser PaidMedia) -> Value -> Parser PaidMedia
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
width_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"width"
Maybe Int
height_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"height"
Maybe Int
duration_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"duration"
Maybe Minithumbnail
minithumbnail_ <- Object
o Object -> Key -> Parser (Maybe Minithumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"minithumbnail"
PaidMedia -> Parser PaidMedia
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaidMedia -> Parser PaidMedia) -> PaidMedia -> Parser PaidMedia
forall a b. (a -> b) -> a -> b
$ PaidMediaPreview
{ width :: Maybe Int
width = Maybe Int
width_
, height :: Maybe Int
height = Maybe Int
height_
, duration :: Maybe Int
duration = Maybe Int
duration_
, minithumbnail :: Maybe Minithumbnail
minithumbnail = Maybe Minithumbnail
minithumbnail_
}
parsePaidMediaPhoto :: A.Value -> AT.Parser PaidMedia
parsePaidMediaPhoto :: Value -> Parser PaidMedia
parsePaidMediaPhoto = String -> (Object -> Parser PaidMedia) -> Value -> Parser PaidMedia
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaidMediaPhoto" ((Object -> Parser PaidMedia) -> Value -> Parser PaidMedia)
-> (Object -> Parser PaidMedia) -> Value -> Parser PaidMedia
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"
PaidMedia -> Parser PaidMedia
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaidMedia -> Parser PaidMedia) -> PaidMedia -> Parser PaidMedia
forall a b. (a -> b) -> a -> b
$ PaidMediaPhoto
{ photo :: Maybe Photo
photo = Maybe Photo
photo_
}
parsePaidMediaVideo :: A.Value -> AT.Parser PaidMedia
parsePaidMediaVideo :: Value -> Parser PaidMedia
parsePaidMediaVideo = String -> (Object -> Parser PaidMedia) -> Value -> Parser PaidMedia
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PaidMediaVideo" ((Object -> Parser PaidMedia) -> Value -> Parser PaidMedia)
-> (Object -> Parser PaidMedia) -> Value -> Parser PaidMedia
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"
PaidMedia -> Parser PaidMedia
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PaidMedia -> Parser PaidMedia) -> PaidMedia -> Parser PaidMedia
forall a b. (a -> b) -> a -> b
$ PaidMediaVideo
{ video :: Maybe Video
video = Maybe Video
video_
}
parseJSON Value
_ = Parser PaidMedia
forall a. Monoid a => a
mempty