module TD.Data.DraftMessage
( DraftMessage(..)
, defaultDraftMessage
) 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.InputMessageReplyTo as InputMessageReplyTo
import qualified TD.Data.InputMessageContent as InputMessageContent
data DraftMessage
= DraftMessage
{ DraftMessage -> Maybe InputMessageReplyTo
reply_to :: Maybe InputMessageReplyTo.InputMessageReplyTo
, DraftMessage -> Maybe Int
date :: Maybe Int
, DraftMessage -> Maybe InputMessageContent
input_message_text :: Maybe InputMessageContent.InputMessageContent
, DraftMessage -> Maybe Int
effect_id :: Maybe Int
}
deriving (DraftMessage -> DraftMessage -> Bool
(DraftMessage -> DraftMessage -> Bool)
-> (DraftMessage -> DraftMessage -> Bool) -> Eq DraftMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DraftMessage -> DraftMessage -> Bool
== :: DraftMessage -> DraftMessage -> Bool
$c/= :: DraftMessage -> DraftMessage -> Bool
/= :: DraftMessage -> DraftMessage -> Bool
Eq, Int -> DraftMessage -> ShowS
[DraftMessage] -> ShowS
DraftMessage -> String
(Int -> DraftMessage -> ShowS)
-> (DraftMessage -> String)
-> ([DraftMessage] -> ShowS)
-> Show DraftMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DraftMessage -> ShowS
showsPrec :: Int -> DraftMessage -> ShowS
$cshow :: DraftMessage -> String
show :: DraftMessage -> String
$cshowList :: [DraftMessage] -> ShowS
showList :: [DraftMessage] -> ShowS
Show)
instance I.ShortShow DraftMessage where
shortShow :: DraftMessage -> String
shortShow DraftMessage
{ reply_to :: DraftMessage -> Maybe InputMessageReplyTo
reply_to = Maybe InputMessageReplyTo
reply_to_
, date :: DraftMessage -> Maybe Int
date = Maybe Int
date_
, input_message_text :: DraftMessage -> Maybe InputMessageContent
input_message_text = Maybe InputMessageContent
input_message_text_
, effect_id :: DraftMessage -> Maybe Int
effect_id = Maybe Int
effect_id_
}
= String
"DraftMessage"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"reply_to" String -> Maybe InputMessageReplyTo -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputMessageReplyTo
reply_to_
, String
"date" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
date_
, String
"input_message_text" String -> Maybe InputMessageContent -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe InputMessageContent
input_message_text_
, String
"effect_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
effect_id_
]
instance AT.FromJSON DraftMessage where
parseJSON :: Value -> Parser DraftMessage
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
"draftMessage" -> Value -> Parser DraftMessage
parseDraftMessage Value
v
String
_ -> Parser DraftMessage
forall a. Monoid a => a
mempty
where
parseDraftMessage :: A.Value -> AT.Parser DraftMessage
parseDraftMessage :: Value -> Parser DraftMessage
parseDraftMessage = String
-> (Object -> Parser DraftMessage) -> Value -> Parser DraftMessage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"DraftMessage" ((Object -> Parser DraftMessage) -> Value -> Parser DraftMessage)
-> (Object -> Parser DraftMessage) -> Value -> Parser DraftMessage
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe InputMessageReplyTo
reply_to_ <- Object
o Object -> Key -> Parser (Maybe InputMessageReplyTo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"reply_to"
Maybe Int
date_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"date"
Maybe InputMessageContent
input_message_text_ <- Object
o Object -> Key -> Parser (Maybe InputMessageContent)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"input_message_text"
Maybe Int
effect_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
"effect_id"
DraftMessage -> Parser DraftMessage
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DraftMessage -> Parser DraftMessage)
-> DraftMessage -> Parser DraftMessage
forall a b. (a -> b) -> a -> b
$ DraftMessage
{ reply_to :: Maybe InputMessageReplyTo
reply_to = Maybe InputMessageReplyTo
reply_to_
, date :: Maybe Int
date = Maybe Int
date_
, input_message_text :: Maybe InputMessageContent
input_message_text = Maybe InputMessageContent
input_message_text_
, effect_id :: Maybe Int
effect_id = Maybe Int
effect_id_
}
parseJSON Value
_ = Parser DraftMessage
forall a. Monoid a => a
mempty
instance AT.ToJSON DraftMessage where
toJSON :: DraftMessage -> Value
toJSON DraftMessage
{ reply_to :: DraftMessage -> Maybe InputMessageReplyTo
reply_to = Maybe InputMessageReplyTo
reply_to_
, date :: DraftMessage -> Maybe Int
date = Maybe Int
date_
, input_message_text :: DraftMessage -> Maybe InputMessageContent
input_message_text = Maybe InputMessageContent
input_message_text_
, effect_id :: DraftMessage -> Maybe Int
effect_id = Maybe Int
effect_id_
}
= [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
"draftMessage"
, Key
"reply_to" Key -> Maybe InputMessageReplyTo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputMessageReplyTo
reply_to_
, Key
"date" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Int
date_
, Key
"input_message_text" Key -> Maybe InputMessageContent -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe InputMessageContent
input_message_text_
, Key
"effect_id" Key -> Maybe Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= (Int -> Value) -> Maybe Int -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Int -> Value
I.writeInt64 Maybe Int
effect_id_
]
defaultDraftMessage :: DraftMessage
defaultDraftMessage :: DraftMessage
defaultDraftMessage =
DraftMessage
{ reply_to :: Maybe InputMessageReplyTo
reply_to = Maybe InputMessageReplyTo
forall a. Maybe a
Nothing
, date :: Maybe Int
date = Maybe Int
forall a. Maybe a
Nothing
, input_message_text :: Maybe InputMessageContent
input_message_text = Maybe InputMessageContent
forall a. Maybe a
Nothing
, effect_id :: Maybe Int
effect_id = Maybe Int
forall a. Maybe a
Nothing
}