module TD.Data.InputVideoNote
( InputVideoNote(..)
, defaultInputVideoNote
) 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.InputFile as InputFile
import qualified TD.Data.InputThumbnail as InputThumbnail
data InputVideoNote
= InputVideoNote
{ InputVideoNote -> Maybe InputFile
video_note :: Maybe InputFile.InputFile
, InputVideoNote -> Maybe InputThumbnail
thumbnail :: Maybe InputThumbnail.InputThumbnail
, InputVideoNote -> Maybe Int
duration :: Maybe Int
, InputVideoNote -> Maybe Int
_length :: Maybe Int
}
deriving (InputVideoNote -> InputVideoNote -> Bool
(InputVideoNote -> InputVideoNote -> Bool)
-> (InputVideoNote -> InputVideoNote -> Bool) -> Eq InputVideoNote
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputVideoNote -> InputVideoNote -> Bool
== :: InputVideoNote -> InputVideoNote -> Bool
$c/= :: InputVideoNote -> InputVideoNote -> Bool
/= :: InputVideoNote -> InputVideoNote -> Bool
Eq, Int -> InputVideoNote -> ShowS
[InputVideoNote] -> ShowS
InputVideoNote -> String
(Int -> InputVideoNote -> ShowS)
-> (InputVideoNote -> String)
-> ([InputVideoNote] -> ShowS)
-> Show InputVideoNote
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputVideoNote -> ShowS
showsPrec :: Int -> InputVideoNote -> ShowS
$cshow :: InputVideoNote -> String
show :: InputVideoNote -> String
$cshowList :: [InputVideoNote] -> ShowS
showList :: [InputVideoNote] -> ShowS
Show)
instance I.ShortShow InputVideoNote where
shortShow :: InputVideoNote -> String
shortShow InputVideoNote
{ video_note :: InputVideoNote -> Maybe InputFile
video_note = Maybe InputFile
video_note_
, thumbnail :: InputVideoNote -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, duration :: InputVideoNote -> Maybe Int
duration = Maybe Int
duration_
, _length :: InputVideoNote -> Maybe Int
_length = Maybe Int
_length_
}
= String
"InputVideoNote"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"video_note" String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
video_note_
, String
"thumbnail" String -> Maybe InputThumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputThumbnail
thumbnail_
, String
"duration" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
duration_
, String
"_length" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_length_
]
instance AT.FromJSON InputVideoNote where
parseJSON :: Value -> Parser InputVideoNote
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
"inputVideoNote" -> Value -> Parser InputVideoNote
parseInputVideoNote Value
v
String
_ -> Parser InputVideoNote
forall a. Monoid a => a
mempty
where
parseInputVideoNote :: A.Value -> AT.Parser InputVideoNote
parseInputVideoNote :: Value -> Parser InputVideoNote
parseInputVideoNote = String
-> (Object -> Parser InputVideoNote)
-> Value
-> Parser InputVideoNote
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputVideoNote" ((Object -> Parser InputVideoNote)
-> Value -> Parser InputVideoNote)
-> (Object -> Parser InputVideoNote)
-> Value
-> Parser InputVideoNote
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe InputFile
video_note_ <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"video_note"
Maybe InputThumbnail
thumbnail_ <- Object
o Object -> Key -> Parser (Maybe InputThumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"thumbnail"
Maybe Int
duration_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"duration"
Maybe Int
_length_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"length"
InputVideoNote -> Parser InputVideoNote
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputVideoNote -> Parser InputVideoNote)
-> InputVideoNote -> Parser InputVideoNote
forall a b. (a -> b) -> a -> b
$ InputVideoNote
{ video_note :: Maybe InputFile
video_note = Maybe InputFile
video_note_
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, duration :: Maybe Int
duration = Maybe Int
duration_
, _length :: Maybe Int
_length = Maybe Int
_length_
}
parseJSON Value
_ = Parser InputVideoNote
forall a. Monoid a => a
mempty
instance AT.ToJSON InputVideoNote where
toJSON :: InputVideoNote -> Value
toJSON InputVideoNote
{ video_note :: InputVideoNote -> Maybe InputFile
video_note = Maybe InputFile
video_note_
, thumbnail :: InputVideoNote -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, duration :: InputVideoNote -> Maybe Int
duration = Maybe Int
duration_
, _length :: InputVideoNote -> Maybe Int
_length = Maybe Int
_length_
}
= [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
"inputVideoNote"
, Key
"video_note" Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
video_note_
, Key
"thumbnail" Key -> Maybe InputThumbnail -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputThumbnail
thumbnail_
, 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
"length" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
_length_
]
defaultInputVideoNote :: InputVideoNote
defaultInputVideoNote :: InputVideoNote
defaultInputVideoNote =
InputVideoNote
{ video_note :: Maybe InputFile
video_note = Maybe InputFile
forall a. Maybe a
Nothing
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
forall a. Maybe a
Nothing
, duration :: Maybe Int
duration = Maybe Int
forall a. Maybe a
Nothing
, _length :: Maybe Int
_length = Maybe Int
forall a. Maybe a
Nothing
}