module TD.Data.InputPaidMediaType
(InputPaidMediaType(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data InputPaidMediaType
= InputPaidMediaTypePhoto
| InputPaidMediaTypeVideo
{ InputPaidMediaType -> Maybe Int
duration :: Maybe Int
, InputPaidMediaType -> Maybe Bool
supports_streaming :: Maybe Bool
}
deriving (InputPaidMediaType -> InputPaidMediaType -> Bool
(InputPaidMediaType -> InputPaidMediaType -> Bool)
-> (InputPaidMediaType -> InputPaidMediaType -> Bool)
-> Eq InputPaidMediaType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputPaidMediaType -> InputPaidMediaType -> Bool
== :: InputPaidMediaType -> InputPaidMediaType -> Bool
$c/= :: InputPaidMediaType -> InputPaidMediaType -> Bool
/= :: InputPaidMediaType -> InputPaidMediaType -> Bool
Eq, Int -> InputPaidMediaType -> ShowS
[InputPaidMediaType] -> ShowS
InputPaidMediaType -> String
(Int -> InputPaidMediaType -> ShowS)
-> (InputPaidMediaType -> String)
-> ([InputPaidMediaType] -> ShowS)
-> Show InputPaidMediaType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputPaidMediaType -> ShowS
showsPrec :: Int -> InputPaidMediaType -> ShowS
$cshow :: InputPaidMediaType -> String
show :: InputPaidMediaType -> String
$cshowList :: [InputPaidMediaType] -> ShowS
showList :: [InputPaidMediaType] -> ShowS
Show)
instance I.ShortShow InputPaidMediaType where
shortShow :: InputPaidMediaType -> String
shortShow InputPaidMediaType
InputPaidMediaTypePhoto
= String
"InputPaidMediaTypePhoto"
shortShow InputPaidMediaTypeVideo
{ duration :: InputPaidMediaType -> Maybe Int
duration = Maybe Int
duration_
, supports_streaming :: InputPaidMediaType -> Maybe Bool
supports_streaming = Maybe Bool
supports_streaming_
}
= String
"InputPaidMediaTypeVideo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"duration" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
duration_
, String
"supports_streaming" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
supports_streaming_
]
instance AT.FromJSON InputPaidMediaType where
parseJSON :: Value -> Parser InputPaidMediaType
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
"inputPaidMediaTypePhoto" -> InputPaidMediaType -> Parser InputPaidMediaType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure InputPaidMediaType
InputPaidMediaTypePhoto
String
"inputPaidMediaTypeVideo" -> Value -> Parser InputPaidMediaType
parseInputPaidMediaTypeVideo Value
v
String
_ -> Parser InputPaidMediaType
forall a. Monoid a => a
mempty
where
parseInputPaidMediaTypeVideo :: A.Value -> AT.Parser InputPaidMediaType
parseInputPaidMediaTypeVideo :: Value -> Parser InputPaidMediaType
parseInputPaidMediaTypeVideo = String
-> (Object -> Parser InputPaidMediaType)
-> Value
-> Parser InputPaidMediaType
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputPaidMediaTypeVideo" ((Object -> Parser InputPaidMediaType)
-> Value -> Parser InputPaidMediaType)
-> (Object -> Parser InputPaidMediaType)
-> Value
-> Parser InputPaidMediaType
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
duration_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"duration"
Maybe Bool
supports_streaming_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"supports_streaming"
InputPaidMediaType -> Parser InputPaidMediaType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputPaidMediaType -> Parser InputPaidMediaType)
-> InputPaidMediaType -> Parser InputPaidMediaType
forall a b. (a -> b) -> a -> b
$ InputPaidMediaTypeVideo
{ duration :: Maybe Int
duration = Maybe Int
duration_
, supports_streaming :: Maybe Bool
supports_streaming = Maybe Bool
supports_streaming_
}
parseJSON Value
_ = Parser InputPaidMediaType
forall a. Monoid a => a
mempty
instance AT.ToJSON InputPaidMediaType where
toJSON :: InputPaidMediaType -> Value
toJSON InputPaidMediaType
InputPaidMediaTypePhoto
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"inputPaidMediaTypePhoto"
]
toJSON InputPaidMediaTypeVideo
{ duration :: InputPaidMediaType -> Maybe Int
duration = Maybe Int
duration_
, supports_streaming :: InputPaidMediaType -> Maybe Bool
supports_streaming = Maybe Bool
supports_streaming_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"inputPaidMediaTypeVideo"
, Key
"duration" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
duration_
, Key
"supports_streaming" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
supports_streaming_
]