module TD.Data.Sticker
(Sticker(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified TD.Data.StickerFormat as StickerFormat
import qualified TD.Data.StickerFullType as StickerFullType
import qualified TD.Data.Thumbnail as Thumbnail
import qualified TD.Data.File as File
data Sticker
= Sticker
{ Sticker -> Maybe Int
_id :: Maybe Int
, Sticker -> Maybe Int
set_id :: Maybe Int
, Sticker -> Maybe Int
width :: Maybe Int
, Sticker -> Maybe Int
height :: Maybe Int
, Sticker -> Maybe Text
emoji :: Maybe T.Text
, Sticker -> Maybe StickerFormat
format :: Maybe StickerFormat.StickerFormat
, Sticker -> Maybe StickerFullType
full_type :: Maybe StickerFullType.StickerFullType
, Sticker -> Maybe Thumbnail
thumbnail :: Maybe Thumbnail.Thumbnail
, Sticker -> Maybe File
sticker :: Maybe File.File
}
deriving (Sticker -> Sticker -> Bool
(Sticker -> Sticker -> Bool)
-> (Sticker -> Sticker -> Bool) -> Eq Sticker
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Sticker -> Sticker -> Bool
== :: Sticker -> Sticker -> Bool
$c/= :: Sticker -> Sticker -> Bool
/= :: Sticker -> Sticker -> Bool
Eq, Int -> Sticker -> ShowS
[Sticker] -> ShowS
Sticker -> String
(Int -> Sticker -> ShowS)
-> (Sticker -> String) -> ([Sticker] -> ShowS) -> Show Sticker
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Sticker -> ShowS
showsPrec :: Int -> Sticker -> ShowS
$cshow :: Sticker -> String
show :: Sticker -> String
$cshowList :: [Sticker] -> ShowS
showList :: [Sticker] -> ShowS
Show)
instance I.ShortShow Sticker where
shortShow :: Sticker -> String
shortShow Sticker
{ _id :: Sticker -> Maybe Int
_id = Maybe Int
_id_
, set_id :: Sticker -> Maybe Int
set_id = Maybe Int
set_id_
, width :: Sticker -> Maybe Int
width = Maybe Int
width_
, height :: Sticker -> Maybe Int
height = Maybe Int
height_
, emoji :: Sticker -> Maybe Text
emoji = Maybe Text
emoji_
, format :: Sticker -> Maybe StickerFormat
format = Maybe StickerFormat
format_
, full_type :: Sticker -> Maybe StickerFullType
full_type = Maybe StickerFullType
full_type_
, thumbnail :: Sticker -> Maybe Thumbnail
thumbnail = Maybe Thumbnail
thumbnail_
, sticker :: Sticker -> Maybe File
sticker = Maybe File
sticker_
}
= String
"Sticker"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"set_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
set_id_
, 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
"emoji" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
emoji_
, String
"format" String -> Maybe StickerFormat -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StickerFormat
format_
, String
"full_type" String -> Maybe StickerFullType -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe StickerFullType
full_type_
, String
"thumbnail" String -> Maybe Thumbnail -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Thumbnail
thumbnail_
, String
"sticker" String -> Maybe File -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe File
sticker_
]
instance AT.FromJSON Sticker where
parseJSON :: Value -> Parser Sticker
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
"sticker" -> Value -> Parser Sticker
parseSticker Value
v
String
_ -> Parser Sticker
forall a. Monoid a => a
mempty
where
parseSticker :: A.Value -> AT.Parser Sticker
parseSticker :: Value -> Parser Sticker
parseSticker = String -> (Object -> Parser Sticker) -> Value -> Parser Sticker
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"Sticker" ((Object -> Parser Sticker) -> Value -> Parser Sticker)
-> (Object -> Parser Sticker) -> Value -> Parser Sticker
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe Int
set_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"set_id"
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 Text
emoji_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"emoji"
Maybe StickerFormat
format_ <- Object
o Object -> Key -> Parser (Maybe StickerFormat)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"format"
Maybe StickerFullType
full_type_ <- Object
o Object -> Key -> Parser (Maybe StickerFullType)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"full_type"
Maybe Thumbnail
thumbnail_ <- Object
o Object -> Key -> Parser (Maybe Thumbnail)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"thumbnail"
Maybe File
sticker_ <- Object
o Object -> Key -> Parser (Maybe File)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sticker"
Sticker -> Parser Sticker
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Sticker -> Parser Sticker) -> Sticker -> Parser Sticker
forall a b. (a -> b) -> a -> b
$ Sticker
{ _id :: Maybe Int
_id = Maybe Int
_id_
, set_id :: Maybe Int
set_id = Maybe Int
set_id_
, width :: Maybe Int
width = Maybe Int
width_
, height :: Maybe Int
height = Maybe Int
height_
, emoji :: Maybe Text
emoji = Maybe Text
emoji_
, format :: Maybe StickerFormat
format = Maybe StickerFormat
format_
, full_type :: Maybe StickerFullType
full_type = Maybe StickerFullType
full_type_
, thumbnail :: Maybe Thumbnail
thumbnail = Maybe Thumbnail
thumbnail_
, sticker :: Maybe File
sticker = Maybe File
sticker_
}
parseJSON Value
_ = Parser Sticker
forall a. Monoid a => a
mempty