module TD.Data.PreparedInlineMessage
  (PreparedInlineMessage(..)) 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.InlineQueryResult as InlineQueryResult
import qualified TD.Data.TargetChatTypes as TargetChatTypes

data PreparedInlineMessage
  = PreparedInlineMessage -- ^ Represents a ready to send inline message. Use sendInlineQueryResultMessage to send the message
    { PreparedInlineMessage -> Maybe Int
inline_query_id :: Maybe Int                                 -- ^ Unique identifier of the inline query to pass to sendInlineQueryResultMessage
    , PreparedInlineMessage -> Maybe InlineQueryResult
result          :: Maybe InlineQueryResult.InlineQueryResult -- ^ Resulted inline message of the query
    , PreparedInlineMessage -> Maybe TargetChatTypes
chat_types      :: Maybe TargetChatTypes.TargetChatTypes     -- ^ Types of the chats to which the message can be sent
    }
  deriving (PreparedInlineMessage -> PreparedInlineMessage -> Bool
(PreparedInlineMessage -> PreparedInlineMessage -> Bool)
-> (PreparedInlineMessage -> PreparedInlineMessage -> Bool)
-> Eq PreparedInlineMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PreparedInlineMessage -> PreparedInlineMessage -> Bool
== :: PreparedInlineMessage -> PreparedInlineMessage -> Bool
$c/= :: PreparedInlineMessage -> PreparedInlineMessage -> Bool
/= :: PreparedInlineMessage -> PreparedInlineMessage -> Bool
Eq, Int -> PreparedInlineMessage -> ShowS
[PreparedInlineMessage] -> ShowS
PreparedInlineMessage -> String
(Int -> PreparedInlineMessage -> ShowS)
-> (PreparedInlineMessage -> String)
-> ([PreparedInlineMessage] -> ShowS)
-> Show PreparedInlineMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PreparedInlineMessage -> ShowS
showsPrec :: Int -> PreparedInlineMessage -> ShowS
$cshow :: PreparedInlineMessage -> String
show :: PreparedInlineMessage -> String
$cshowList :: [PreparedInlineMessage] -> ShowS
showList :: [PreparedInlineMessage] -> ShowS
Show)

instance I.ShortShow PreparedInlineMessage where
  shortShow :: PreparedInlineMessage -> String
shortShow PreparedInlineMessage
    { inline_query_id :: PreparedInlineMessage -> Maybe Int
inline_query_id = Maybe Int
inline_query_id_
    , result :: PreparedInlineMessage -> Maybe InlineQueryResult
result          = Maybe InlineQueryResult
result_
    , chat_types :: PreparedInlineMessage -> Maybe TargetChatTypes
chat_types      = Maybe TargetChatTypes
chat_types_
    }
      = String
"PreparedInlineMessage"
        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
"result"          String -> Maybe InlineQueryResult -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InlineQueryResult
result_
        , String
"chat_types"      String -> Maybe TargetChatTypes -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe TargetChatTypes
chat_types_
        ]

instance AT.FromJSON PreparedInlineMessage where
  parseJSON :: Value -> Parser PreparedInlineMessage
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
"preparedInlineMessage" -> Value -> Parser PreparedInlineMessage
parsePreparedInlineMessage Value
v
      String
_                       -> Parser PreparedInlineMessage
forall a. Monoid a => a
mempty
    
    where
      parsePreparedInlineMessage :: A.Value -> AT.Parser PreparedInlineMessage
      parsePreparedInlineMessage :: Value -> Parser PreparedInlineMessage
parsePreparedInlineMessage = String
-> (Object -> Parser PreparedInlineMessage)
-> Value
-> Parser PreparedInlineMessage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PreparedInlineMessage" ((Object -> Parser PreparedInlineMessage)
 -> Value -> Parser PreparedInlineMessage)
-> (Object -> Parser PreparedInlineMessage)
-> Value
-> Parser PreparedInlineMessage
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 InlineQueryResult
result_          <- Object
o Object -> Key -> Parser (Maybe InlineQueryResult)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"result"
        Maybe TargetChatTypes
chat_types_      <- Object
o Object -> Key -> Parser (Maybe TargetChatTypes)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?                       Key
"chat_types"
        PreparedInlineMessage -> Parser PreparedInlineMessage
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PreparedInlineMessage -> Parser PreparedInlineMessage)
-> PreparedInlineMessage -> Parser PreparedInlineMessage
forall a b. (a -> b) -> a -> b
$ PreparedInlineMessage
          { inline_query_id :: Maybe Int
inline_query_id = Maybe Int
inline_query_id_
          , result :: Maybe InlineQueryResult
result          = Maybe InlineQueryResult
result_
          , chat_types :: Maybe TargetChatTypes
chat_types      = Maybe TargetChatTypes
chat_types_
          }
  parseJSON Value
_ = Parser PreparedInlineMessage
forall a. Monoid a => a
mempty