module TD.Data.PreparedInlineMessageId
  (PreparedInlineMessageId(..)) where

import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T

data PreparedInlineMessageId
  = PreparedInlineMessageId -- ^ Represents an inline message that can be sent via the bot
    { PreparedInlineMessageId -> Maybe Text
_id             :: Maybe T.Text -- ^ Unique identifier for the message
    , PreparedInlineMessageId -> Maybe Int
expiration_date :: Maybe Int    -- ^ Point in time (Unix timestamp) when the message can't be used anymore
    }
  deriving (PreparedInlineMessageId -> PreparedInlineMessageId -> Bool
(PreparedInlineMessageId -> PreparedInlineMessageId -> Bool)
-> (PreparedInlineMessageId -> PreparedInlineMessageId -> Bool)
-> Eq PreparedInlineMessageId
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PreparedInlineMessageId -> PreparedInlineMessageId -> Bool
== :: PreparedInlineMessageId -> PreparedInlineMessageId -> Bool
$c/= :: PreparedInlineMessageId -> PreparedInlineMessageId -> Bool
/= :: PreparedInlineMessageId -> PreparedInlineMessageId -> Bool
Eq, Int -> PreparedInlineMessageId -> ShowS
[PreparedInlineMessageId] -> ShowS
PreparedInlineMessageId -> String
(Int -> PreparedInlineMessageId -> ShowS)
-> (PreparedInlineMessageId -> String)
-> ([PreparedInlineMessageId] -> ShowS)
-> Show PreparedInlineMessageId
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PreparedInlineMessageId -> ShowS
showsPrec :: Int -> PreparedInlineMessageId -> ShowS
$cshow :: PreparedInlineMessageId -> String
show :: PreparedInlineMessageId -> String
$cshowList :: [PreparedInlineMessageId] -> ShowS
showList :: [PreparedInlineMessageId] -> ShowS
Show)

instance I.ShortShow PreparedInlineMessageId where
  shortShow :: PreparedInlineMessageId -> String
shortShow PreparedInlineMessageId
    { _id :: PreparedInlineMessageId -> Maybe Text
_id             = Maybe Text
_id_
    , expiration_date :: PreparedInlineMessageId -> Maybe Int
expiration_date = Maybe Int
expiration_date_
    }
      = String
"PreparedInlineMessageId"
        String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
        [ String
"_id"             String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
_id_
        , String
"expiration_date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
expiration_date_
        ]

instance AT.FromJSON PreparedInlineMessageId where
  parseJSON :: Value -> Parser PreparedInlineMessageId
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
"preparedInlineMessageId" -> Value -> Parser PreparedInlineMessageId
parsePreparedInlineMessageId Value
v
      String
_                         -> Parser PreparedInlineMessageId
forall a. Monoid a => a
mempty
    
    where
      parsePreparedInlineMessageId :: A.Value -> AT.Parser PreparedInlineMessageId
      parsePreparedInlineMessageId :: Value -> Parser PreparedInlineMessageId
parsePreparedInlineMessageId = String
-> (Object -> Parser PreparedInlineMessageId)
-> Value
-> Parser PreparedInlineMessageId
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"PreparedInlineMessageId" ((Object -> Parser PreparedInlineMessageId)
 -> Value -> Parser PreparedInlineMessageId)
-> (Object -> Parser PreparedInlineMessageId)
-> Value
-> Parser PreparedInlineMessageId
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
        Maybe Text
_id_             <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"id"
        Maybe Int
expiration_date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:?  Key
"expiration_date"
        PreparedInlineMessageId -> Parser PreparedInlineMessageId
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PreparedInlineMessageId -> Parser PreparedInlineMessageId)
-> PreparedInlineMessageId -> Parser PreparedInlineMessageId
forall a b. (a -> b) -> a -> b
$ PreparedInlineMessageId
          { _id :: Maybe Text
_id             = Maybe Text
_id_
          , expiration_date :: Maybe Int
expiration_date = Maybe Int
expiration_date_
          }
  parseJSON Value
_ = Parser PreparedInlineMessageId
forall a. Monoid a => a
mempty