module TD.Data.MessageForwardInfo
(MessageForwardInfo(..)) 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.MessageOrigin as MessageOrigin
import qualified TD.Data.ForwardSource as ForwardSource
import qualified Data.Text as T
data MessageForwardInfo
= MessageForwardInfo
{ MessageForwardInfo -> Maybe MessageOrigin
origin :: Maybe MessageOrigin.MessageOrigin
, MessageForwardInfo -> Maybe Int
date :: Maybe Int
, MessageForwardInfo -> Maybe ForwardSource
source :: Maybe ForwardSource.ForwardSource
, MessageForwardInfo -> Maybe Text
public_service_announcement_type :: Maybe T.Text
}
deriving (MessageForwardInfo -> MessageForwardInfo -> Bool
(MessageForwardInfo -> MessageForwardInfo -> Bool)
-> (MessageForwardInfo -> MessageForwardInfo -> Bool)
-> Eq MessageForwardInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageForwardInfo -> MessageForwardInfo -> Bool
== :: MessageForwardInfo -> MessageForwardInfo -> Bool
$c/= :: MessageForwardInfo -> MessageForwardInfo -> Bool
/= :: MessageForwardInfo -> MessageForwardInfo -> Bool
Eq, Int -> MessageForwardInfo -> ShowS
[MessageForwardInfo] -> ShowS
MessageForwardInfo -> String
(Int -> MessageForwardInfo -> ShowS)
-> (MessageForwardInfo -> String)
-> ([MessageForwardInfo] -> ShowS)
-> Show MessageForwardInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageForwardInfo -> ShowS
showsPrec :: Int -> MessageForwardInfo -> ShowS
$cshow :: MessageForwardInfo -> String
show :: MessageForwardInfo -> String
$cshowList :: [MessageForwardInfo] -> ShowS
showList :: [MessageForwardInfo] -> ShowS
Show)
instance I.ShortShow MessageForwardInfo where
shortShow :: MessageForwardInfo -> String
shortShow MessageForwardInfo
{ origin :: MessageForwardInfo -> Maybe MessageOrigin
origin = Maybe MessageOrigin
origin_
, date :: MessageForwardInfo -> Maybe Int
date = Maybe Int
date_
, source :: MessageForwardInfo -> Maybe ForwardSource
source = Maybe ForwardSource
source_
, public_service_announcement_type :: MessageForwardInfo -> Maybe Text
public_service_announcement_type = Maybe Text
public_service_announcement_type_
}
= String
"MessageForwardInfo"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"origin" String -> Maybe MessageOrigin -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageOrigin
origin_
, String
"date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
, String
"source" String -> Maybe ForwardSource -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ForwardSource
source_
, String
"public_service_announcement_type" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
public_service_announcement_type_
]
instance AT.FromJSON MessageForwardInfo where
parseJSON :: Value -> Parser MessageForwardInfo
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
"messageForwardInfo" -> Value -> Parser MessageForwardInfo
parseMessageForwardInfo Value
v
String
_ -> Parser MessageForwardInfo
forall a. Monoid a => a
mempty
where
parseMessageForwardInfo :: A.Value -> AT.Parser MessageForwardInfo
parseMessageForwardInfo :: Value -> Parser MessageForwardInfo
parseMessageForwardInfo = String
-> (Object -> Parser MessageForwardInfo)
-> Value
-> Parser MessageForwardInfo
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MessageForwardInfo" ((Object -> Parser MessageForwardInfo)
-> Value -> Parser MessageForwardInfo)
-> (Object -> Parser MessageForwardInfo)
-> Value
-> Parser MessageForwardInfo
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe MessageOrigin
origin_ <- Object
o Object -> Key -> Parser (Maybe MessageOrigin)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"origin"
Maybe Int
date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"date"
Maybe ForwardSource
source_ <- Object
o Object -> Key -> Parser (Maybe ForwardSource)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"source"
Maybe Text
public_service_announcement_type_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"public_service_announcement_type"
MessageForwardInfo -> Parser MessageForwardInfo
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MessageForwardInfo -> Parser MessageForwardInfo)
-> MessageForwardInfo -> Parser MessageForwardInfo
forall a b. (a -> b) -> a -> b
$ MessageForwardInfo
{ origin :: Maybe MessageOrigin
origin = Maybe MessageOrigin
origin_
, date :: Maybe Int
date = Maybe Int
date_
, source :: Maybe ForwardSource
source = Maybe ForwardSource
source_
, public_service_announcement_type :: Maybe Text
public_service_announcement_type = Maybe Text
public_service_announcement_type_
}
parseJSON Value
_ = Parser MessageForwardInfo
forall a. Monoid a => a
mempty