module TD.Data.EmojiCategory
(EmojiCategory(..)) 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.Sticker as Sticker
import qualified TD.Data.EmojiCategorySource as EmojiCategorySource
data EmojiCategory
= EmojiCategory
{ EmojiCategory -> Maybe Text
name :: Maybe T.Text
, EmojiCategory -> Maybe Sticker
icon :: Maybe Sticker.Sticker
, EmojiCategory -> Maybe EmojiCategorySource
source :: Maybe EmojiCategorySource.EmojiCategorySource
, EmojiCategory -> Maybe Bool
is_greeting :: Maybe Bool
}
deriving (EmojiCategory -> EmojiCategory -> Bool
(EmojiCategory -> EmojiCategory -> Bool)
-> (EmojiCategory -> EmojiCategory -> Bool) -> Eq EmojiCategory
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EmojiCategory -> EmojiCategory -> Bool
== :: EmojiCategory -> EmojiCategory -> Bool
$c/= :: EmojiCategory -> EmojiCategory -> Bool
/= :: EmojiCategory -> EmojiCategory -> Bool
Eq, Int -> EmojiCategory -> ShowS
[EmojiCategory] -> ShowS
EmojiCategory -> String
(Int -> EmojiCategory -> ShowS)
-> (EmojiCategory -> String)
-> ([EmojiCategory] -> ShowS)
-> Show EmojiCategory
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EmojiCategory -> ShowS
showsPrec :: Int -> EmojiCategory -> ShowS
$cshow :: EmojiCategory -> String
show :: EmojiCategory -> String
$cshowList :: [EmojiCategory] -> ShowS
showList :: [EmojiCategory] -> ShowS
Show)
instance I.ShortShow EmojiCategory where
shortShow :: EmojiCategory -> String
shortShow EmojiCategory
{ name :: EmojiCategory -> Maybe Text
name = Maybe Text
name_
, icon :: EmojiCategory -> Maybe Sticker
icon = Maybe Sticker
icon_
, source :: EmojiCategory -> Maybe EmojiCategorySource
source = Maybe EmojiCategorySource
source_
, is_greeting :: EmojiCategory -> Maybe Bool
is_greeting = Maybe Bool
is_greeting_
}
= String
"EmojiCategory"
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
"icon" String -> Maybe Sticker -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Sticker
icon_
, String
"source" String -> Maybe EmojiCategorySource -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe EmojiCategorySource
source_
, String
"is_greeting" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_greeting_
]
instance AT.FromJSON EmojiCategory where
parseJSON :: Value -> Parser EmojiCategory
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
"emojiCategory" -> Value -> Parser EmojiCategory
parseEmojiCategory Value
v
String
_ -> Parser EmojiCategory
forall a. Monoid a => a
mempty
where
parseEmojiCategory :: A.Value -> AT.Parser EmojiCategory
parseEmojiCategory :: Value -> Parser EmojiCategory
parseEmojiCategory = String
-> (Object -> Parser EmojiCategory)
-> Value
-> Parser EmojiCategory
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"EmojiCategory" ((Object -> Parser EmojiCategory) -> Value -> Parser EmojiCategory)
-> (Object -> Parser EmojiCategory)
-> Value
-> Parser EmojiCategory
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 Sticker
icon_ <- Object
o Object -> Key -> Parser (Maybe Sticker)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"icon"
Maybe EmojiCategorySource
source_ <- Object
o Object -> Key -> Parser (Maybe EmojiCategorySource)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"source"
Maybe Bool
is_greeting_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_greeting"
EmojiCategory -> Parser EmojiCategory
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (EmojiCategory -> Parser EmojiCategory)
-> EmojiCategory -> Parser EmojiCategory
forall a b. (a -> b) -> a -> b
$ EmojiCategory
{ name :: Maybe Text
name = Maybe Text
name_
, icon :: Maybe Sticker
icon = Maybe Sticker
icon_
, source :: Maybe EmojiCategorySource
source = Maybe EmojiCategorySource
source_
, is_greeting :: Maybe Bool
is_greeting = Maybe Bool
is_greeting_
}
parseJSON Value
_ = Parser EmojiCategory
forall a. Monoid a => a
mempty