module TD.Data.TextCompositionStyle
(TextCompositionStyle(..)) 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
data TextCompositionStyle
= TextCompositionStyle
{ TextCompositionStyle -> Maybe Text
name :: Maybe T.Text
, TextCompositionStyle -> Maybe Int
custom_emoji_id :: Maybe Int
, TextCompositionStyle -> Maybe Text
title :: Maybe T.Text
}
deriving (TextCompositionStyle -> TextCompositionStyle -> Bool
(TextCompositionStyle -> TextCompositionStyle -> Bool)
-> (TextCompositionStyle -> TextCompositionStyle -> Bool)
-> Eq TextCompositionStyle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextCompositionStyle -> TextCompositionStyle -> Bool
== :: TextCompositionStyle -> TextCompositionStyle -> Bool
$c/= :: TextCompositionStyle -> TextCompositionStyle -> Bool
/= :: TextCompositionStyle -> TextCompositionStyle -> Bool
Eq, Int -> TextCompositionStyle -> ShowS
[TextCompositionStyle] -> ShowS
TextCompositionStyle -> String
(Int -> TextCompositionStyle -> ShowS)
-> (TextCompositionStyle -> String)
-> ([TextCompositionStyle] -> ShowS)
-> Show TextCompositionStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextCompositionStyle -> ShowS
showsPrec :: Int -> TextCompositionStyle -> ShowS
$cshow :: TextCompositionStyle -> String
show :: TextCompositionStyle -> String
$cshowList :: [TextCompositionStyle] -> ShowS
showList :: [TextCompositionStyle] -> ShowS
Show)
instance I.ShortShow TextCompositionStyle where
shortShow :: TextCompositionStyle -> String
shortShow TextCompositionStyle
{ name :: TextCompositionStyle -> Maybe Text
name = Maybe Text
name_
, custom_emoji_id :: TextCompositionStyle -> Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
, title :: TextCompositionStyle -> Maybe Text
title = Maybe Text
title_
}
= String
"TextCompositionStyle"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"name" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
name_
, String
"custom_emoji_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
custom_emoji_id_
, String
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
]
instance AT.FromJSON TextCompositionStyle where
parseJSON :: Value -> Parser TextCompositionStyle
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
"textCompositionStyle" -> Value -> Parser TextCompositionStyle
parseTextCompositionStyle Value
v
String
_ -> Parser TextCompositionStyle
forall a. Monoid a => a
mempty
where
parseTextCompositionStyle :: A.Value -> AT.Parser TextCompositionStyle
parseTextCompositionStyle :: Value -> Parser TextCompositionStyle
parseTextCompositionStyle = String
-> (Object -> Parser TextCompositionStyle)
-> Value
-> Parser TextCompositionStyle
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"TextCompositionStyle" ((Object -> Parser TextCompositionStyle)
-> Value -> Parser TextCompositionStyle)
-> (Object -> Parser TextCompositionStyle)
-> Value
-> Parser TextCompositionStyle
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
name_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"name"
Maybe Int
custom_emoji_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
"custom_emoji_id"
Maybe Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
TextCompositionStyle -> Parser TextCompositionStyle
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TextCompositionStyle -> Parser TextCompositionStyle)
-> TextCompositionStyle -> Parser TextCompositionStyle
forall a b. (a -> b) -> a -> b
$ TextCompositionStyle
{ name :: Maybe Text
name = Maybe Text
name_
, custom_emoji_id :: Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
, title :: Maybe Text
title = Maybe Text
title_
}
parseJSON Value
_ = Parser TextCompositionStyle
forall a. Monoid a => a
mempty