module TD.Data.InputSticker
( InputSticker(..)
, defaultInputSticker
) 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 InputSticker
= InputSticker
{ InputSticker -> Maybe InputFile
sticker :: Maybe InputFile.InputFile
, InputSticker -> Maybe InputThumbnail
thumbnail :: Maybe InputThumbnail.InputThumbnail
, InputSticker -> Maybe Int
width :: Maybe Int
, InputSticker -> Maybe Int
height :: Maybe Int
}
deriving (InputSticker -> InputSticker -> Bool
(InputSticker -> InputSticker -> Bool)
-> (InputSticker -> InputSticker -> Bool) -> Eq InputSticker
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputSticker -> InputSticker -> Bool
== :: InputSticker -> InputSticker -> Bool
$c/= :: InputSticker -> InputSticker -> Bool
/= :: InputSticker -> InputSticker -> Bool
Eq, Int -> InputSticker -> ShowS
[InputSticker] -> ShowS
InputSticker -> String
(Int -> InputSticker -> ShowS)
-> (InputSticker -> String)
-> ([InputSticker] -> ShowS)
-> Show InputSticker
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputSticker -> ShowS
showsPrec :: Int -> InputSticker -> ShowS
$cshow :: InputSticker -> String
show :: InputSticker -> String
$cshowList :: [InputSticker] -> ShowS
showList :: [InputSticker] -> ShowS
Show)
instance I.ShortShow InputSticker where
shortShow :: InputSticker -> String
shortShow InputSticker
{ sticker :: InputSticker -> Maybe InputFile
sticker = Maybe InputFile
sticker_
, thumbnail :: InputSticker -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, width :: InputSticker -> Maybe Int
width = Maybe Int
width_
, height :: InputSticker -> Maybe Int
height = Maybe Int
height_
}
= String
"InputSticker"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"sticker" String -> Maybe InputFile -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputFile
sticker_
, String
"thumbnail" String -> Maybe InputThumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputThumbnail
thumbnail_
, 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 InputSticker where
parseJSON :: Value -> Parser InputSticker
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
"inputSticker" -> Value -> Parser InputSticker
parseInputSticker Value
v
String
_ -> Parser InputSticker
forall a. Monoid a => a
mempty
where
parseInputSticker :: A.Value -> AT.Parser InputSticker
parseInputSticker :: Value -> Parser InputSticker
parseInputSticker = String
-> (Object -> Parser InputSticker) -> Value -> Parser InputSticker
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputSticker" ((Object -> Parser InputSticker) -> Value -> Parser InputSticker)
-> (Object -> Parser InputSticker) -> Value -> Parser InputSticker
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe InputFile
sticker_ <- Object
o Object -> Key -> Parser (Maybe InputFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sticker"
Maybe InputThumbnail
thumbnail_ <- Object
o Object -> Key -> Parser (Maybe InputThumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"thumbnail"
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"
InputSticker -> Parser InputSticker
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputSticker -> Parser InputSticker)
-> InputSticker -> Parser InputSticker
forall a b. (a -> b) -> a -> b
$ InputSticker
{ sticker :: Maybe InputFile
sticker = Maybe InputFile
sticker_
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, width :: Maybe Int
width = Maybe Int
width_
, height :: Maybe Int
height = Maybe Int
height_
}
parseJSON Value
_ = Parser InputSticker
forall a. Monoid a => a
mempty
instance AT.ToJSON InputSticker where
toJSON :: InputSticker -> Value
toJSON InputSticker
{ sticker :: InputSticker -> Maybe InputFile
sticker = Maybe InputFile
sticker_
, thumbnail :: InputSticker -> Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
thumbnail_
, width :: InputSticker -> Maybe Int
width = Maybe Int
width_
, height :: InputSticker -> 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
"inputSticker"
, Key
"sticker" Key -> Maybe InputFile -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputFile
sticker_
, 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
"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_
]
defaultInputSticker :: InputSticker
defaultInputSticker :: InputSticker
defaultInputSticker =
InputSticker
{ sticker :: Maybe InputFile
sticker = Maybe InputFile
forall a. Maybe a
Nothing
, thumbnail :: Maybe InputThumbnail
thumbnail = Maybe InputThumbnail
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
}