module TD.Data.InputPollOption
( InputPollOption(..)
, defaultInputPollOption
) 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.FormattedText as FormattedText
data InputPollOption
= InputPollOption
{ InputPollOption -> Maybe FormattedText
text :: Maybe FormattedText.FormattedText
}
deriving (InputPollOption -> InputPollOption -> Bool
(InputPollOption -> InputPollOption -> Bool)
-> (InputPollOption -> InputPollOption -> Bool)
-> Eq InputPollOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InputPollOption -> InputPollOption -> Bool
== :: InputPollOption -> InputPollOption -> Bool
$c/= :: InputPollOption -> InputPollOption -> Bool
/= :: InputPollOption -> InputPollOption -> Bool
Eq, Int -> InputPollOption -> ShowS
[InputPollOption] -> ShowS
InputPollOption -> String
(Int -> InputPollOption -> ShowS)
-> (InputPollOption -> String)
-> ([InputPollOption] -> ShowS)
-> Show InputPollOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InputPollOption -> ShowS
showsPrec :: Int -> InputPollOption -> ShowS
$cshow :: InputPollOption -> String
show :: InputPollOption -> String
$cshowList :: [InputPollOption] -> ShowS
showList :: [InputPollOption] -> ShowS
Show)
instance I.ShortShow InputPollOption where
shortShow :: InputPollOption -> String
shortShow InputPollOption
{ text :: InputPollOption -> Maybe FormattedText
text = Maybe FormattedText
text_
}
= String
"InputPollOption"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"text" String -> Maybe FormattedText -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe FormattedText
text_
]
instance AT.FromJSON InputPollOption where
parseJSON :: Value -> Parser InputPollOption
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
"inputPollOption" -> Value -> Parser InputPollOption
parseInputPollOption Value
v
String
_ -> Parser InputPollOption
forall a. Monoid a => a
mempty
where
parseInputPollOption :: A.Value -> AT.Parser InputPollOption
parseInputPollOption :: Value -> Parser InputPollOption
parseInputPollOption = String
-> (Object -> Parser InputPollOption)
-> Value
-> Parser InputPollOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InputPollOption" ((Object -> Parser InputPollOption)
-> Value -> Parser InputPollOption)
-> (Object -> Parser InputPollOption)
-> Value
-> Parser InputPollOption
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe FormattedText
text_ <- Object
o Object -> Key -> Parser (Maybe FormattedText)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"text"
InputPollOption -> Parser InputPollOption
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputPollOption -> Parser InputPollOption)
-> InputPollOption -> Parser InputPollOption
forall a b. (a -> b) -> a -> b
$ InputPollOption
{ text :: Maybe FormattedText
text = Maybe FormattedText
text_
}
parseJSON Value
_ = Parser InputPollOption
forall a. Monoid a => a
mempty
instance AT.ToJSON InputPollOption where
toJSON :: InputPollOption -> Value
toJSON InputPollOption
{ text :: InputPollOption -> Maybe FormattedText
text = Maybe FormattedText
text_
}
= [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
"inputPollOption"
, Key
"text" Key -> Maybe FormattedText -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe FormattedText
text_
]
defaultInputPollOption :: InputPollOption
defaultInputPollOption :: InputPollOption
defaultInputPollOption =
InputPollOption
{ text :: Maybe FormattedText
text = Maybe FormattedText
forall a. Maybe a
Nothing
}