module TD.Data.SponsoredMessage
(SponsoredMessage(..)) 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.MessageContent as MessageContent
import qualified TD.Data.MessageSponsor as MessageSponsor
import qualified Data.Text as T
data
=
{ SponsoredMessage -> Maybe Int
message_id :: Maybe Int
, SponsoredMessage -> Maybe Bool
is_recommended :: Maybe Bool
, SponsoredMessage -> Maybe Bool
can_be_reported :: Maybe Bool
, SponsoredMessage -> Maybe MessageContent
content :: Maybe MessageContent.MessageContent
, :: Maybe MessageSponsor.MessageSponsor
, SponsoredMessage -> Maybe Text
title :: Maybe T.Text
, SponsoredMessage -> Maybe Text
button_text :: Maybe T.Text
, SponsoredMessage -> Maybe Int
accent_color_id :: Maybe Int
, SponsoredMessage -> Maybe Int
background_custom_emoji_id :: Maybe Int
, SponsoredMessage -> Maybe Text
additional_info :: Maybe T.Text
}
deriving (SponsoredMessage -> SponsoredMessage -> Bool
(SponsoredMessage -> SponsoredMessage -> Bool)
-> (SponsoredMessage -> SponsoredMessage -> Bool)
-> Eq SponsoredMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SponsoredMessage -> SponsoredMessage -> Bool
== :: SponsoredMessage -> SponsoredMessage -> Bool
$c/= :: SponsoredMessage -> SponsoredMessage -> Bool
/= :: SponsoredMessage -> SponsoredMessage -> Bool
Eq, Int -> SponsoredMessage -> ShowS
[SponsoredMessage] -> ShowS
SponsoredMessage -> String
(Int -> SponsoredMessage -> ShowS)
-> (SponsoredMessage -> String)
-> ([SponsoredMessage] -> ShowS)
-> Show SponsoredMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SponsoredMessage -> ShowS
showsPrec :: Int -> SponsoredMessage -> ShowS
$cshow :: SponsoredMessage -> String
show :: SponsoredMessage -> String
$cshowList :: [SponsoredMessage] -> ShowS
showList :: [SponsoredMessage] -> ShowS
Show)
instance I.ShortShow SponsoredMessage where
shortShow :: SponsoredMessage -> String
shortShow SponsoredMessage
{ message_id :: SponsoredMessage -> Maybe Int
message_id = Maybe Int
message_id_
, is_recommended :: SponsoredMessage -> Maybe Bool
is_recommended = Maybe Bool
is_recommended_
, can_be_reported :: SponsoredMessage -> Maybe Bool
can_be_reported = Maybe Bool
can_be_reported_
, content :: SponsoredMessage -> Maybe MessageContent
content = Maybe MessageContent
content_
, sponsor :: SponsoredMessage -> Maybe MessageSponsor
sponsor = Maybe MessageSponsor
sponsor_
, title :: SponsoredMessage -> Maybe Text
title = Maybe Text
title_
, button_text :: SponsoredMessage -> Maybe Text
button_text = Maybe Text
button_text_
, accent_color_id :: SponsoredMessage -> Maybe Int
accent_color_id = Maybe Int
accent_color_id_
, background_custom_emoji_id :: SponsoredMessage -> Maybe Int
background_custom_emoji_id = Maybe Int
background_custom_emoji_id_
, additional_info :: SponsoredMessage -> Maybe Text
additional_info = Maybe Text
additional_info_
}
= String
"SponsoredMessage"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
message_id_
, String
"is_recommended" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_recommended_
, String
"can_be_reported" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_be_reported_
, String
"content" String -> Maybe MessageContent -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageContent
content_
, String
"sponsor" String -> Maybe MessageSponsor -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSponsor
sponsor_
, String
"title" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
title_
, String
"button_text" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
button_text_
, String
"accent_color_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
accent_color_id_
, String
"background_custom_emoji_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
background_custom_emoji_id_
, String
"additional_info" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
additional_info_
]
instance AT.FromJSON SponsoredMessage where
parseJSON :: Value -> Parser SponsoredMessage
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
"sponsoredMessage" -> Value -> Parser SponsoredMessage
parseSponsoredMessage Value
v
String
_ -> Parser SponsoredMessage
forall a. Monoid a => a
mempty
where
parseSponsoredMessage :: A.Value -> AT.Parser SponsoredMessage
parseSponsoredMessage :: Value -> Parser SponsoredMessage
parseSponsoredMessage = String
-> (Object -> Parser SponsoredMessage)
-> Value
-> Parser SponsoredMessage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"SponsoredMessage" ((Object -> Parser SponsoredMessage)
-> Value -> Parser SponsoredMessage)
-> (Object -> Parser SponsoredMessage)
-> Value
-> Parser SponsoredMessage
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"message_id"
Maybe Bool
is_recommended_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_recommended"
Maybe Bool
can_be_reported_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_be_reported"
Maybe MessageContent
content_ <- Object
o Object -> Key -> Parser (Maybe MessageContent)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"content"
Maybe MessageSponsor
sponsor_ <- Object
o Object -> Key -> Parser (Maybe MessageSponsor)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sponsor"
Maybe Text
title_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"title"
Maybe Text
button_text_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"button_text"
Maybe Int
accent_color_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"accent_color_id"
Maybe Int
background_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
"background_custom_emoji_id"
Maybe Text
additional_info_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"additional_info"
SponsoredMessage -> Parser SponsoredMessage
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SponsoredMessage -> Parser SponsoredMessage)
-> SponsoredMessage -> Parser SponsoredMessage
forall a b. (a -> b) -> a -> b
$ SponsoredMessage
{ message_id :: Maybe Int
message_id = Maybe Int
message_id_
, is_recommended :: Maybe Bool
is_recommended = Maybe Bool
is_recommended_
, can_be_reported :: Maybe Bool
can_be_reported = Maybe Bool
can_be_reported_
, content :: Maybe MessageContent
content = Maybe MessageContent
content_
, sponsor :: Maybe MessageSponsor
sponsor = Maybe MessageSponsor
sponsor_
, title :: Maybe Text
title = Maybe Text
title_
, button_text :: Maybe Text
button_text = Maybe Text
button_text_
, accent_color_id :: Maybe Int
accent_color_id = Maybe Int
accent_color_id_
, background_custom_emoji_id :: Maybe Int
background_custom_emoji_id = Maybe Int
background_custom_emoji_id_
, additional_info :: Maybe Text
additional_info = Maybe Text
additional_info_
}
parseJSON Value
_ = Parser SponsoredMessage
forall a. Monoid a => a
mempty