module TD.Data.PublicForward
(PublicForward(..)) 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.Message as Message
import qualified TD.Data.Story as Story
data PublicForward
= PublicForwardMessage
{ PublicForward -> Maybe Message
message :: Maybe Message.Message
}
| PublicForwardStory
{ PublicForward -> Maybe Story
story :: Maybe Story.Story
}
deriving (PublicForward -> PublicForward -> Bool
(PublicForward -> PublicForward -> Bool)
-> (PublicForward -> PublicForward -> Bool) -> Eq PublicForward
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PublicForward -> PublicForward -> Bool
== :: PublicForward -> PublicForward -> Bool
$c/= :: PublicForward -> PublicForward -> Bool
/= :: PublicForward -> PublicForward -> Bool
Eq, Int -> PublicForward -> ShowS
[PublicForward] -> ShowS
PublicForward -> String
(Int -> PublicForward -> ShowS)
-> (PublicForward -> String)
-> ([PublicForward] -> ShowS)
-> Show PublicForward
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PublicForward -> ShowS
showsPrec :: Int -> PublicForward -> ShowS
$cshow :: PublicForward -> String
show :: PublicForward -> String
$cshowList :: [PublicForward] -> ShowS
showList :: [PublicForward] -> ShowS
Show)
instance I.ShortShow PublicForward where
shortShow :: PublicForward -> String
shortShow PublicForwardMessage
{ message :: PublicForward -> Maybe Message
message = Maybe Message
message_
}
= String
"PublicForwardMessage"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"message" String -> Maybe Message -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Message
message_
]
shortShow PublicForwardStory
{ story :: PublicForward -> Maybe Story
story = Maybe Story
story_
}
= String
"PublicForwardStory"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"story" String -> Maybe Story -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Story
story_
]
instance AT.FromJSON PublicForward where
parseJSON :: Value -> Parser PublicForward
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
"publicForwardMessage" -> Value -> Parser PublicForward
parsePublicForwardMessage Value
v
String
"publicForwardStory" -> Value -> Parser PublicForward
parsePublicForwardStory Value
v
String
_ -> Parser PublicForward
forall a. Monoid a => a
mempty
where
parsePublicForwardMessage :: A.Value -> AT.Parser PublicForward
parsePublicForwardMessage :: Value -> Parser PublicForward
parsePublicForwardMessage = String
-> (Object -> Parser PublicForward)
-> Value
-> Parser PublicForward
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PublicForwardMessage" ((Object -> Parser PublicForward) -> Value -> Parser PublicForward)
-> (Object -> Parser PublicForward)
-> Value
-> Parser PublicForward
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Message
message_ <- Object
o Object -> Key -> Parser (Maybe Message)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"message"
PublicForward -> Parser PublicForward
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PublicForward -> Parser PublicForward)
-> PublicForward -> Parser PublicForward
forall a b. (a -> b) -> a -> b
$ PublicForwardMessage
{ message :: Maybe Message
message = Maybe Message
message_
}
parsePublicForwardStory :: A.Value -> AT.Parser PublicForward
parsePublicForwardStory :: Value -> Parser PublicForward
parsePublicForwardStory = String
-> (Object -> Parser PublicForward)
-> Value
-> Parser PublicForward
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PublicForwardStory" ((Object -> Parser PublicForward) -> Value -> Parser PublicForward)
-> (Object -> Parser PublicForward)
-> Value
-> Parser PublicForward
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Story
story_ <- Object
o Object -> Key -> Parser (Maybe Story)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"story"
PublicForward -> Parser PublicForward
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PublicForward -> Parser PublicForward)
-> PublicForward -> Parser PublicForward
forall a b. (a -> b) -> a -> b
$ PublicForwardStory
{ story :: Maybe Story
story = Maybe Story
story_
}
parseJSON Value
_ = Parser PublicForward
forall a. Monoid a => a
mempty