module TD.Data.ForumTopicIcon
( ForumTopicIcon(..)
, defaultForumTopicIcon
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
data ForumTopicIcon
= ForumTopicIcon
{ ForumTopicIcon -> Maybe Int
color :: Maybe Int
, ForumTopicIcon -> Maybe Int
custom_emoji_id :: Maybe Int
}
deriving (ForumTopicIcon -> ForumTopicIcon -> Bool
(ForumTopicIcon -> ForumTopicIcon -> Bool)
-> (ForumTopicIcon -> ForumTopicIcon -> Bool) -> Eq ForumTopicIcon
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ForumTopicIcon -> ForumTopicIcon -> Bool
== :: ForumTopicIcon -> ForumTopicIcon -> Bool
$c/= :: ForumTopicIcon -> ForumTopicIcon -> Bool
/= :: ForumTopicIcon -> ForumTopicIcon -> Bool
Eq, Int -> ForumTopicIcon -> ShowS
[ForumTopicIcon] -> ShowS
ForumTopicIcon -> String
(Int -> ForumTopicIcon -> ShowS)
-> (ForumTopicIcon -> String)
-> ([ForumTopicIcon] -> ShowS)
-> Show ForumTopicIcon
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ForumTopicIcon -> ShowS
showsPrec :: Int -> ForumTopicIcon -> ShowS
$cshow :: ForumTopicIcon -> String
show :: ForumTopicIcon -> String
$cshowList :: [ForumTopicIcon] -> ShowS
showList :: [ForumTopicIcon] -> ShowS
Show)
instance I.ShortShow ForumTopicIcon where
shortShow :: ForumTopicIcon -> String
shortShow ForumTopicIcon
{ color :: ForumTopicIcon -> Maybe Int
color = Maybe Int
color_
, custom_emoji_id :: ForumTopicIcon -> Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
}
= String
"ForumTopicIcon"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"color" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
color_
, String
"custom_emoji_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
custom_emoji_id_
]
instance AT.FromJSON ForumTopicIcon where
parseJSON :: Value -> Parser ForumTopicIcon
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
"forumTopicIcon" -> Value -> Parser ForumTopicIcon
parseForumTopicIcon Value
v
String
_ -> Parser ForumTopicIcon
forall a. Monoid a => a
mempty
where
parseForumTopicIcon :: A.Value -> AT.Parser ForumTopicIcon
parseForumTopicIcon :: Value -> Parser ForumTopicIcon
parseForumTopicIcon = String
-> (Object -> Parser ForumTopicIcon)
-> Value
-> Parser ForumTopicIcon
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ForumTopicIcon" ((Object -> Parser ForumTopicIcon)
-> Value -> Parser ForumTopicIcon)
-> (Object -> Parser ForumTopicIcon)
-> Value
-> Parser ForumTopicIcon
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
color_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"color"
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"
ForumTopicIcon -> Parser ForumTopicIcon
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ForumTopicIcon -> Parser ForumTopicIcon)
-> ForumTopicIcon -> Parser ForumTopicIcon
forall a b. (a -> b) -> a -> b
$ ForumTopicIcon
{ color :: Maybe Int
color = Maybe Int
color_
, custom_emoji_id :: Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
}
parseJSON Value
_ = Parser ForumTopicIcon
forall a. Monoid a => a
mempty
instance AT.ToJSON ForumTopicIcon where
toJSON :: ForumTopicIcon -> Value
toJSON ForumTopicIcon
{ color :: ForumTopicIcon -> Maybe Int
color = Maybe Int
color_
, custom_emoji_id :: ForumTopicIcon -> Maybe Int
custom_emoji_id = Maybe Int
custom_emoji_id_
}
= [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
"forumTopicIcon"
, Key
"color" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
color_
, Key
"custom_emoji_id" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64 Maybe Int
custom_emoji_id_
]
defaultForumTopicIcon :: ForumTopicIcon
defaultForumTopicIcon :: ForumTopicIcon
defaultForumTopicIcon =
ForumTopicIcon
{ color :: Maybe Int
color = Maybe Int
forall a. Maybe a
Nothing
, custom_emoji_id :: Maybe Int
custom_emoji_id = Maybe Int
forall a. Maybe a
Nothing
}