module TD.Data.InputPaidMedia
( InputPaidMedia(..)
, defaultInputPaidMedia
) 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.InputPaidMediaType as InputPaidMediaType
import qualified TD.Data.InputFile as InputFile
import qualified TD.Data.InputThumbnail as InputThumbnail
data InputPaidMedia
= InputPaidMedia
{ InputPaidMedia -> Maybe InputPaidMediaType
_type :: Maybe InputPaidMediaType.InputPaidMediaType
, InputPaidMedia -> Maybe InputFile
media :: Maybe InputFile.InputFile
, InputPaidMedia -> Maybe InputThumbnail
thumbnail :: Maybe InputThumbnail.InputThumbnail
, InputPaidMedia -> Maybe [Int]
added_sticker_file_ids :: Maybe [Int]
, InputPaidMedia -> Maybe Int
width :: Maybe Int
, InputPaidMedia -> Maybe Int
height :: Maybe Int
}
deriving (InputPaidMedia -> InputPaidMedia -> Bool
(InputPaidMedia -> InputPaidMedia -> Bool)
-> (InputPaidMedia -> InputPaidMedia -> Bool) -> Eq InputPaidMedia
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputPaidMedia -> InputPaidMedia -> Bool
== :: InputPaidMedia -> InputPaidMedia -> Bool
$c/= :: InputPaidMedia -> InputPaidMedia -> Bool
/= :: InputPaidMedia -> InputPaidMedia -> Bool
Eq, Int -> InputPaidMedia -> ShowS
[InputPaidMedia] -> ShowS
InputPaidMedia -> String
(Int -> InputPaidMedia -> ShowS)
-> (InputPaidMedia -> String)
-> ([InputPaidMedia] -> ShowS)
-> Show InputPaidMedia
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputPaidMedia -> ShowS
showsPrec :: Int -> InputPaidMedia -> ShowS
$cshow :: InputPaidMedia -> String
show :: InputPaidMedia -> String
$cshowList :: [InputPaidMedia] -> ShowS
showList :: [InputPaidMedia] -> ShowS
Show)
instance I.ShortShow InputPaidMedia where
shortShow :: InputPaidMedia -> String
shortShow InputPaidMedia
{ _type :: InputPaidMedia -> Maybe InputPaidMediaType
_type = Maybe InputPaidMediaType
_type_
, media :: InputPaidMedia -> Maybe InputFile
media = Maybe InputFile
media_
, thumbnail :: InputPaidMedia -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, added_sticker_file_ids :: InputPaidMedia -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
, width :: InputPaidMedia -> Maybe Int
width = Maybe Int
width_
, height :: InputPaidMedia -> Maybe Int
height = Maybe Int
height_
}
= String
"InputPaidMedia"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_type" String -> Maybe InputPaidMediaType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputPaidMediaType
_type_
, String
"media" String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
media_
, String
"thumbnail" String -> Maybe InputThumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputThumbnail
thumbnail_
, String
"added_sticker_file_ids" String -> Maybe [Int] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [Int]
added_sticker_file_ids_
, 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_
]
instance AT.FromJSON InputPaidMedia where
parseJSON :: Value -> Parser InputPaidMedia
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
"inputPaidMedia" -> Value -> Parser InputPaidMedia
parseInputPaidMedia Value
v
String
_ -> Parser InputPaidMedia
forall a. Monoid a => a
mempty
where
parseInputPaidMedia :: A.Value -> AT.Parser InputPaidMedia
parseInputPaidMedia :: Value -> Parser InputPaidMedia
parseInputPaidMedia = String
-> (Object -> Parser InputPaidMedia)
-> Value
-> Parser InputPaidMedia
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputPaidMedia" ((Object -> Parser InputPaidMedia)
-> Value -> Parser InputPaidMedia)
-> (Object -> Parser InputPaidMedia)
-> Value
-> Parser InputPaidMedia
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe InputPaidMediaType
_type_ <- Object
o Object -> Key -> Parser (Maybe InputPaidMediaType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"type"
Maybe InputFile
media_ <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"media"
Maybe InputThumbnail
thumbnail_ <- Object
o Object -> Key -> Parser (Maybe InputThumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"thumbnail"
Maybe [Int]
added_sticker_file_ids_ <- Object
o Object -> Key -> Parser (Maybe [Int])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"added_sticker_file_ids"
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"
InputPaidMedia -> Parser InputPaidMedia
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputPaidMedia -> Parser InputPaidMedia)
-> InputPaidMedia -> Parser InputPaidMedia
forall a b. (a -> b) -> a -> b
$ InputPaidMedia
{ _type :: Maybe InputPaidMediaType
_type = Maybe InputPaidMediaType
_type_
, media :: Maybe InputFile
media = Maybe InputFile
media_
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
, width :: Maybe Int
width = Maybe Int
width_
, height :: Maybe Int
height = Maybe Int
height_
}
parseJSON Value
_ = Parser InputPaidMedia
forall a. Monoid a => a
mempty
instance AT.ToJSON InputPaidMedia where
toJSON :: InputPaidMedia -> Value
toJSON InputPaidMedia
{ _type :: InputPaidMedia -> Maybe InputPaidMediaType
_type = Maybe InputPaidMediaType
_type_
, media :: InputPaidMedia -> Maybe InputFile
media = Maybe InputFile
media_
, thumbnail :: InputPaidMedia -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, added_sticker_file_ids :: InputPaidMedia -> Maybe [Int]
added_sticker_file_ids = Maybe [Int]
added_sticker_file_ids_
, width :: InputPaidMedia -> Maybe Int
width = Maybe Int
width_
, height :: InputPaidMedia -> Maybe Int
height = Maybe Int
height_
}
= [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
"inputPaidMedia"
, Key
"type" Key -> Maybe InputPaidMediaType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputPaidMediaType
_type_
, Key
"media" Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
media_
, 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
"added_sticker_file_ids" Key -> Maybe [Int] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [Int]
added_sticker_file_ids_
, Key
"width" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
width_
, Key
"height" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
height_
]
defaultInputPaidMedia :: InputPaidMedia
defaultInputPaidMedia :: InputPaidMedia
defaultInputPaidMedia =
InputPaidMedia
{ _type :: Maybe InputPaidMediaType
_type = Maybe InputPaidMediaType
forall a. Maybe a
Nothing
, media :: Maybe InputFile
media = Maybe InputFile
forall a. Maybe a
Nothing
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
forall a. Maybe a
Nothing
, added_sticker_file_ids :: Maybe [Int]
added_sticker_file_ids = Maybe [Int]
forall a. Maybe a
Nothing
, width :: Maybe Int
width = Maybe Int
forall a. Maybe a
Nothing
, height :: Maybe Int
height = Maybe Int
forall a. Maybe a
Nothing
}