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