module TD.Data.InlineQueryResults
(InlineQueryResults(..)) 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.InlineQueryResultsButton as InlineQueryResultsButton
import qualified TD.Data.InlineQueryResult as InlineQueryResult
import qualified Data.Text as T
data InlineQueryResults
= InlineQueryResults
{ InlineQueryResults -> Maybe Int
inline_query_id :: Maybe Int
, InlineQueryResults -> Maybe InlineQueryResultsButton
button :: Maybe InlineQueryResultsButton.InlineQueryResultsButton
, InlineQueryResults -> Maybe [InlineQueryResult]
results :: Maybe [InlineQueryResult.InlineQueryResult]
, InlineQueryResults -> Maybe Text
next_offset :: Maybe T.Text
}
deriving (InlineQueryResults -> InlineQueryResults -> Bool
(InlineQueryResults -> InlineQueryResults -> Bool)
-> (InlineQueryResults -> InlineQueryResults -> Bool)
-> Eq InlineQueryResults
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: InlineQueryResults -> InlineQueryResults -> Bool
== :: InlineQueryResults -> InlineQueryResults -> Bool
$c/= :: InlineQueryResults -> InlineQueryResults -> Bool
/= :: InlineQueryResults -> InlineQueryResults -> Bool
Eq, Int -> InlineQueryResults -> ShowS
[InlineQueryResults] -> ShowS
InlineQueryResults -> String
(Int -> InlineQueryResults -> ShowS)
-> (InlineQueryResults -> String)
-> ([InlineQueryResults] -> ShowS)
-> Show InlineQueryResults
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InlineQueryResults -> ShowS
showsPrec :: Int -> InlineQueryResults -> ShowS
$cshow :: InlineQueryResults -> String
show :: InlineQueryResults -> String
$cshowList :: [InlineQueryResults] -> ShowS
showList :: [InlineQueryResults] -> ShowS
Show)
instance I.ShortShow InlineQueryResults where
shortShow :: InlineQueryResults -> String
shortShow InlineQueryResults
{ inline_query_id :: InlineQueryResults -> Maybe Int
inline_query_id = Maybe Int
inline_query_id_
, button :: InlineQueryResults -> Maybe InlineQueryResultsButton
button = Maybe InlineQueryResultsButton
button_
, results :: InlineQueryResults -> Maybe [InlineQueryResult]
results = Maybe [InlineQueryResult]
results_
, next_offset :: InlineQueryResults -> Maybe Text
next_offset = Maybe Text
next_offset_
}
= String
"InlineQueryResults"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"inline_query_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
inline_query_id_
, String
"button" String -> Maybe InlineQueryResultsButton -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InlineQueryResultsButton
button_
, String
"results" String -> Maybe [InlineQueryResult] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [InlineQueryResult]
results_
, String
"next_offset" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
next_offset_
]
instance AT.FromJSON InlineQueryResults where
parseJSON :: Value -> Parser InlineQueryResults
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
"inlineQueryResults" -> Value -> Parser InlineQueryResults
parseInlineQueryResults Value
v
String
_ -> Parser InlineQueryResults
forall a. Monoid a => a
mempty
where
parseInlineQueryResults :: A.Value -> AT.Parser InlineQueryResults
parseInlineQueryResults :: Value -> Parser InlineQueryResults
parseInlineQueryResults = String
-> (Object -> Parser InlineQueryResults)
-> Value
-> Parser InlineQueryResults
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"InlineQueryResults" ((Object -> Parser InlineQueryResults)
-> Value -> Parser InlineQueryResults)
-> (Object -> Parser InlineQueryResults)
-> Value
-> Parser InlineQueryResults
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
inline_query_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
"inline_query_id"
Maybe InlineQueryResultsButton
button_ <- Object
o Object -> Key -> Parser (Maybe InlineQueryResultsButton)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"button"
Maybe [InlineQueryResult]
results_ <- Object
o Object -> Key -> Parser (Maybe [InlineQueryResult])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"results"
Maybe Text
next_offset_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"next_offset"
InlineQueryResults -> Parser InlineQueryResults
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InlineQueryResults -> Parser InlineQueryResults)
-> InlineQueryResults -> Parser InlineQueryResults
forall a b. (a -> b) -> a -> b
$ InlineQueryResults
{ inline_query_id :: Maybe Int
inline_query_id = Maybe Int
inline_query_id_
, button :: Maybe InlineQueryResultsButton
button = Maybe InlineQueryResultsButton
button_
, results :: Maybe [InlineQueryResult]
results = Maybe [InlineQueryResult]
results_
, next_offset :: Maybe Text
next_offset = Maybe Text
next_offset_
}
parseJSON Value
_ = Parser InlineQueryResults
forall a. Monoid a => a
mempty